@quillsql/node 0.1.7 → 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 +93 -44
- 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
|
@@ -11,13 +11,49 @@ interface QuillConfig {
|
|
|
11
11
|
stagingDatabaseConnectionString?: string;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
type FieldFormat =
|
|
15
|
+
| "whole_number"
|
|
16
|
+
| "one_decimal_place"
|
|
17
|
+
| "two_decimal_places"
|
|
18
|
+
| "dollar_amount"
|
|
19
|
+
| "MMM_yyyy"
|
|
20
|
+
| "MMM_dd_yyyy"
|
|
21
|
+
| "MMM_dd-MMM_dd"
|
|
22
|
+
| "MMM_dd_hh:mm_ap_pm"
|
|
23
|
+
| "hh_ap_pm"
|
|
24
|
+
| "percent"
|
|
25
|
+
| "string";
|
|
26
|
+
|
|
27
|
+
interface FormattedColumn {
|
|
28
|
+
label: string;
|
|
29
|
+
field: string;
|
|
30
|
+
chartType: string;
|
|
31
|
+
format: FieldFormat;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface QuillRequestMetadata {
|
|
16
35
|
task: string;
|
|
36
|
+
// a query to be run
|
|
17
37
|
query?: string;
|
|
18
|
-
|
|
38
|
+
// a report to be fetched
|
|
19
39
|
id?: string;
|
|
20
|
-
|
|
40
|
+
filters?: any[];
|
|
41
|
+
// dashboard item fields
|
|
42
|
+
name?: string;
|
|
43
|
+
xAxisField?: string;
|
|
44
|
+
yAxisFields?: FormattedColumn[];
|
|
45
|
+
xAxisLabel?: string;
|
|
46
|
+
xAxisFormat?: FieldFormat;
|
|
47
|
+
yAxisLabel?: string;
|
|
48
|
+
chartType?: string;
|
|
49
|
+
dashboardName?: string;
|
|
50
|
+
columns?: FormattedColumn[];
|
|
51
|
+
dateField?: { table: string; field: string };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
interface QuillQueryParams {
|
|
55
|
+
orgId: string;
|
|
56
|
+
metadata: QuillRequestMetadata;
|
|
21
57
|
environment?: string;
|
|
22
58
|
}
|
|
23
59
|
|
|
@@ -35,21 +71,16 @@ module.exports = ({
|
|
|
35
71
|
});
|
|
36
72
|
|
|
37
73
|
return {
|
|
38
|
-
query: async ({
|
|
39
|
-
orgId,
|
|
40
|
-
query,
|
|
41
|
-
filters,
|
|
42
|
-
task,
|
|
43
|
-
id,
|
|
44
|
-
data,
|
|
45
|
-
environment,
|
|
46
|
-
}: QuillQueryParams) => {
|
|
74
|
+
query: async ({ orgId, metadata, environment }: QuillQueryParams) => {
|
|
47
75
|
const targetPool = environment === "STAGING" ? stagingPool : pool;
|
|
76
|
+
const { task, query, id } = metadata;
|
|
77
|
+
console.log("0");
|
|
48
78
|
|
|
49
79
|
if (task === "query") {
|
|
80
|
+
console.log("1");
|
|
50
81
|
const response = await axios.post(
|
|
51
82
|
"https://quill-344421.uc.r.appspot.com/validate",
|
|
52
|
-
{ query },
|
|
83
|
+
{ query: query },
|
|
53
84
|
{
|
|
54
85
|
params: {
|
|
55
86
|
publicKey,
|
|
@@ -75,26 +106,38 @@ module.exports = ({
|
|
|
75
106
|
|
|
76
107
|
if (task === "config") {
|
|
77
108
|
const response = await axios.get(
|
|
78
|
-
"https://quill-344421.uc.r.appspot.com/
|
|
109
|
+
"https://quill-344421.uc.r.appspot.com/config",
|
|
79
110
|
{
|
|
80
111
|
params: {
|
|
81
112
|
publicKey,
|
|
82
113
|
orgId,
|
|
83
114
|
// @ts-ignore
|
|
84
|
-
name:
|
|
115
|
+
name: metadata?.name,
|
|
85
116
|
},
|
|
86
117
|
headers: {
|
|
87
118
|
Authorization: `Bearer ${privateKey}`,
|
|
88
119
|
},
|
|
89
120
|
}
|
|
90
121
|
);
|
|
91
|
-
|
|
122
|
+
let dashConfig = response.data;
|
|
123
|
+
if (dashConfig.filters.length) {
|
|
124
|
+
for (let i = 0; i < dashConfig.filters.length; i++) {
|
|
125
|
+
// parse query
|
|
126
|
+
// run query
|
|
127
|
+
const queryResult = await targetPool.query(
|
|
128
|
+
dashConfig.filters[i].query
|
|
129
|
+
);
|
|
130
|
+
const { rows } = queryResult;
|
|
131
|
+
dashConfig = { options: rows };
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return dashConfig;
|
|
92
135
|
}
|
|
93
136
|
|
|
94
137
|
if (task === "create") {
|
|
95
138
|
const response = await axios.post(
|
|
96
139
|
"https://quill-344421.uc.r.appspot.com/item",
|
|
97
|
-
{
|
|
140
|
+
{ ...metadata },
|
|
98
141
|
{
|
|
99
142
|
params: {
|
|
100
143
|
publicKey,
|
|
@@ -109,41 +152,47 @@ module.exports = ({
|
|
|
109
152
|
}
|
|
110
153
|
|
|
111
154
|
if (task === "item") {
|
|
112
|
-
const response = await axios.
|
|
113
|
-
"https://quill-344421.uc.r.appspot.com/
|
|
114
|
-
{
|
|
115
|
-
params:
|
|
116
|
-
filters && filters.length
|
|
117
|
-
? {
|
|
118
|
-
publicKey,
|
|
119
|
-
orgId,
|
|
120
|
-
filters,
|
|
121
|
-
}
|
|
122
|
-
: { publicKey, orgId },
|
|
123
|
-
headers: {
|
|
124
|
-
Authorization: `Bearer ${privateKey}`,
|
|
125
|
-
},
|
|
126
|
-
}
|
|
127
|
-
);
|
|
128
|
-
const queryResult = await targetPool.query(response.data.query);
|
|
129
|
-
const resp = await axios.get(
|
|
130
|
-
"https://quill-344421.uc.r.appspot.com/selfhostitem",
|
|
155
|
+
const response = await axios.post(
|
|
156
|
+
"https://quill-344421.uc.r.appspot.com/validate",
|
|
157
|
+
{ query },
|
|
131
158
|
{
|
|
132
159
|
params: {
|
|
133
|
-
id,
|
|
134
|
-
orgId,
|
|
135
160
|
publicKey,
|
|
161
|
+
orgId,
|
|
136
162
|
},
|
|
137
163
|
headers: {
|
|
138
164
|
Authorization: `Bearer ${privateKey}`,
|
|
139
165
|
},
|
|
140
166
|
}
|
|
141
167
|
);
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
168
|
+
try {
|
|
169
|
+
const queryResult = await targetPool.query(response.data.query);
|
|
170
|
+
const resp = await axios.get(
|
|
171
|
+
"https://quill-344421.uc.r.appspot.com/selfhostitem",
|
|
172
|
+
{
|
|
173
|
+
params: {
|
|
174
|
+
id,
|
|
175
|
+
orgId,
|
|
176
|
+
publicKey,
|
|
177
|
+
},
|
|
178
|
+
headers: {
|
|
179
|
+
Authorization: `Bearer ${privateKey}`,
|
|
180
|
+
},
|
|
181
|
+
}
|
|
182
|
+
);
|
|
183
|
+
return {
|
|
184
|
+
...resp.data,
|
|
185
|
+
rows: queryResult.rows,
|
|
186
|
+
fields: queryResult.fields,
|
|
187
|
+
};
|
|
188
|
+
} catch (err) {
|
|
189
|
+
return {
|
|
190
|
+
// @ts-ignore
|
|
191
|
+
...err,
|
|
192
|
+
// @ts-ignore
|
|
193
|
+
errorMessage: err && err.message ? err.message : "",
|
|
194
|
+
};
|
|
195
|
+
}
|
|
147
196
|
}
|
|
148
197
|
},
|
|
149
198
|
};
|