@quillsql/node 0.2.7 → 0.2.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/README.md +55 -0
- package/dist/clients/QuillServerClient.js +28 -0
- package/dist/db/CachedPools.js +91 -0
- package/dist/index.ispec.js +41 -0
- package/dist/index.js +103 -0
- package/dist/index.uspec.js +38 -0
- package/dist/models/Cache.js +2 -0
- package/dist/models/Database.js +2 -0
- package/dist/models/Formats.js +2 -0
- package/dist/models/Quill.js +2 -0
- package/dist/utils/Error.js +18 -0
- package/dist/utils/RunQueryProcesses.js +48 -0
- package/examples/node-server/app.ts +35 -0
- package/jest.config.js +19 -0
- package/package.json +26 -15
- package/src/clients/QuillServerClient.ts +23 -0
- package/src/db/CachedPools.ts +97 -0
- package/src/index.ispec.ts +36 -0
- package/src/index.ts +144 -0
- package/src/index.uspec.ts +38 -0
- package/src/models/Cache.ts +18 -0
- package/src/models/Database.ts +5 -0
- package/src/models/Formats.ts +19 -0
- package/src/models/Quill.ts +68 -0
- package/src/utils/Error.ts +21 -0
- package/src/utils/RunQueryProcesses.ts +58 -0
- package/tsconfig.json +11 -106
- package/.gitattributes +0 -2
- package/LICENSE +0 -21
- package/index.js +0 -171
- package/index.ts +0 -272
package/index.js
DELETED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
const { Pool, Connection } = require("pg");
|
|
12
|
-
const axios = require("axios");
|
|
13
|
-
var PgError = require("pg-error");
|
|
14
|
-
Connection.prototype.parseE = PgError.parse;
|
|
15
|
-
Connection.prototype.parseN = PgError.parse;
|
|
16
|
-
const cache = {}; //set the cache
|
|
17
|
-
function setCache(key, value) {
|
|
18
|
-
cache[key] = value;
|
|
19
|
-
}
|
|
20
|
-
function getCache(key) {
|
|
21
|
-
return cache[key];
|
|
22
|
-
}
|
|
23
|
-
module.exports = ({ privateKey, databaseConnectionString, stagingDatabaseConnectionString, }) => {
|
|
24
|
-
const pool = new Pool({
|
|
25
|
-
connectionString: databaseConnectionString,
|
|
26
|
-
ssl: { rejectUnauthorized: false },
|
|
27
|
-
});
|
|
28
|
-
const stagingPool = new Pool({
|
|
29
|
-
connectionString: stagingDatabaseConnectionString,
|
|
30
|
-
});
|
|
31
|
-
return {
|
|
32
|
-
query: ({ orgId, metadata, environment }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
33
|
-
const targetPool = environment === "STAGING" ? stagingPool : pool;
|
|
34
|
-
const { task, query, id } = metadata;
|
|
35
|
-
if (task === "query") {
|
|
36
|
-
try {
|
|
37
|
-
const response = yield axios.post("https://quill-344421.uc.r.appspot.com/validate", {
|
|
38
|
-
query: query,
|
|
39
|
-
orgId: orgId,
|
|
40
|
-
filters: [],
|
|
41
|
-
}, {
|
|
42
|
-
headers: {
|
|
43
|
-
Authorization: `Bearer ${privateKey}`,
|
|
44
|
-
},
|
|
45
|
-
});
|
|
46
|
-
const { fieldToRemove } = response.data;
|
|
47
|
-
const queryResult = yield targetPool.query(response.data.query);
|
|
48
|
-
return Object.assign(Object.assign({}, queryResult), { fields: queryResult.fields.filter(
|
|
49
|
-
// @ts-ignore
|
|
50
|
-
(field) => field.name !== fieldToRemove),
|
|
51
|
-
// @ts-ignore
|
|
52
|
-
rows: queryResult.rows.map((row) => {
|
|
53
|
-
delete row[fieldToRemove];
|
|
54
|
-
return row;
|
|
55
|
-
}) });
|
|
56
|
-
}
|
|
57
|
-
catch (err) {
|
|
58
|
-
return Object.assign(Object.assign({}, err), {
|
|
59
|
-
// @ts-ignore
|
|
60
|
-
errorMessage: err && err.message ? err.message : "" });
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
if (task === "config") {
|
|
64
|
-
try {
|
|
65
|
-
const response = yield axios.get("https://quill-344421.uc.r.appspot.com/config", {
|
|
66
|
-
params: {
|
|
67
|
-
orgId,
|
|
68
|
-
// @ts-ignore
|
|
69
|
-
name: metadata === null || metadata === void 0 ? void 0 : metadata.name,
|
|
70
|
-
},
|
|
71
|
-
headers: {
|
|
72
|
-
Authorization: `Bearer ${privateKey}`,
|
|
73
|
-
},
|
|
74
|
-
});
|
|
75
|
-
let dashConfig = response.data;
|
|
76
|
-
let newFilters = [];
|
|
77
|
-
if (dashConfig.filters && dashConfig.filters.length) {
|
|
78
|
-
for (let i = 0; i < dashConfig.filters.length; i++) {
|
|
79
|
-
const queryResult = yield targetPool.query(dashConfig.filters[i].query);
|
|
80
|
-
const { rows } = queryResult;
|
|
81
|
-
newFilters.push(Object.assign(Object.assign({}, dashConfig.filters[i]), { options: rows }));
|
|
82
|
-
dashConfig.filters[i].options = rows;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
dashConfig = Object.assign(Object.assign({}, dashConfig), { filters: newFilters });
|
|
86
|
-
const { fieldToRemove, newQueries } = response.data;
|
|
87
|
-
if (newQueries) {
|
|
88
|
-
for (const newQuery of newQueries) {
|
|
89
|
-
const { query } = newQuery;
|
|
90
|
-
const cacheKey = `config:${orgId}:${newQuery._id}}`;
|
|
91
|
-
setCache(cacheKey, { fieldToRemove, query });
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
return Object.assign({}, dashConfig);
|
|
95
|
-
}
|
|
96
|
-
catch (_a) {
|
|
97
|
-
return Object.assign(Object.assign({}, err), {
|
|
98
|
-
// @ts-ignore
|
|
99
|
-
errorMessage: err && err.message ? err.message : "" });
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
if (task === "create") {
|
|
103
|
-
try {
|
|
104
|
-
const response = yield axios.post("https://quill-344421.uc.r.appspot.com/item", Object.assign({}, metadata), {
|
|
105
|
-
params: {
|
|
106
|
-
orgId,
|
|
107
|
-
query,
|
|
108
|
-
},
|
|
109
|
-
headers: {
|
|
110
|
-
Authorization: `Bearer ${privateKey}`,
|
|
111
|
-
},
|
|
112
|
-
});
|
|
113
|
-
return response.data;
|
|
114
|
-
}
|
|
115
|
-
catch (_b) {
|
|
116
|
-
return Object.assign(Object.assign({}, err), {
|
|
117
|
-
// @ts-ignore
|
|
118
|
-
errorMessage: err && err.message ? err.message : "" });
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
if (task === "item") {
|
|
122
|
-
try {
|
|
123
|
-
const { filters } = metadata;
|
|
124
|
-
const resp = yield axios.get("https://quill-344421.uc.r.appspot.com/selfhostitem", {
|
|
125
|
-
params: {
|
|
126
|
-
id,
|
|
127
|
-
orgId,
|
|
128
|
-
},
|
|
129
|
-
headers: {
|
|
130
|
-
Authorization: `Bearer ${privateKey}`,
|
|
131
|
-
},
|
|
132
|
-
});
|
|
133
|
-
let fieldToRemove, query;
|
|
134
|
-
if (false &&
|
|
135
|
-
getCache(`config:${orgId}:${id}:${JSON.stringify(filters)}`)) {
|
|
136
|
-
({ fieldToRemove, query } = getCache(`config:${orgId}:${id}:${JSON.stringify(filters)}`));
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
const response = yield axios.post("https://quill-344421.uc.r.appspot.com/validate", {
|
|
140
|
-
dashboardItemId: id,
|
|
141
|
-
query: resp.data.queryString,
|
|
142
|
-
filters: filters,
|
|
143
|
-
orgId: orgId,
|
|
144
|
-
}, {
|
|
145
|
-
headers: {
|
|
146
|
-
Authorization: `Bearer ${privateKey}`,
|
|
147
|
-
},
|
|
148
|
-
});
|
|
149
|
-
({ fieldToRemove, query } = response.data);
|
|
150
|
-
const cacheKey = `config:${orgId}:${id}:${JSON.stringify(filters)}`;
|
|
151
|
-
setCache(cacheKey, { fieldToRemove, query });
|
|
152
|
-
}
|
|
153
|
-
const queryResult = yield targetPool.query(query);
|
|
154
|
-
return Object.assign(Object.assign({}, resp.data), { fields: queryResult.fields.filter(
|
|
155
|
-
// @ts-ignore
|
|
156
|
-
(field) => field.name !== fieldToRemove),
|
|
157
|
-
// @ts-ignore
|
|
158
|
-
rows: queryResult.rows.map((row) => {
|
|
159
|
-
delete row[fieldToRemove];
|
|
160
|
-
return row;
|
|
161
|
-
}) });
|
|
162
|
-
}
|
|
163
|
-
catch (err) {
|
|
164
|
-
return Object.assign(Object.assign({}, err), {
|
|
165
|
-
// @ts-ignore
|
|
166
|
-
errorMessage: err && err.message ? err.message : "" });
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}),
|
|
170
|
-
};
|
|
171
|
-
};
|
package/index.ts
DELETED
|
@@ -1,272 +0,0 @@
|
|
|
1
|
-
const { Pool, Connection } = require("pg");
|
|
2
|
-
const axios = require("axios");
|
|
3
|
-
var PgError = require("pg-error");
|
|
4
|
-
Connection.prototype.parseE = PgError.parse;
|
|
5
|
-
Connection.prototype.parseN = PgError.parse;
|
|
6
|
-
|
|
7
|
-
const cache: any = {}; //set the cache
|
|
8
|
-
|
|
9
|
-
function setCache(key: any, value: any) {
|
|
10
|
-
cache[key] = value;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function getCache(key: any) {
|
|
14
|
-
return cache[key];
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
interface QuillConfig {
|
|
18
|
-
privateKey: string;
|
|
19
|
-
databaseConnectionString: string;
|
|
20
|
-
stagingDatabaseConnectionString?: string;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
type FieldFormat =
|
|
24
|
-
| "whole_number"
|
|
25
|
-
| "one_decimal_place"
|
|
26
|
-
| "two_decimal_places"
|
|
27
|
-
| "dollar_amount"
|
|
28
|
-
| "MMM_yyyy"
|
|
29
|
-
| "MMM_dd_yyyy"
|
|
30
|
-
| "MMM_dd-MMM_dd"
|
|
31
|
-
| "MMM_dd_hh:mm_ap_pm"
|
|
32
|
-
| "hh_ap_pm"
|
|
33
|
-
| "percent"
|
|
34
|
-
| "string";
|
|
35
|
-
interface FormattedColumn {
|
|
36
|
-
label: string;
|
|
37
|
-
field: string;
|
|
38
|
-
chartType: string;
|
|
39
|
-
format: FieldFormat;
|
|
40
|
-
}
|
|
41
|
-
interface QuillRequestMetadata {
|
|
42
|
-
task: string;
|
|
43
|
-
// a query to be run
|
|
44
|
-
query?: string;
|
|
45
|
-
// a report to be fetched
|
|
46
|
-
id?: string;
|
|
47
|
-
filters?: any[];
|
|
48
|
-
// dashboard item fields
|
|
49
|
-
name?: string;
|
|
50
|
-
xAxisField?: string;
|
|
51
|
-
yAxisFields?: FormattedColumn[];
|
|
52
|
-
xAxisLabel?: string;
|
|
53
|
-
xAxisFormat?: FieldFormat;
|
|
54
|
-
yAxisLabel?: string;
|
|
55
|
-
chartType?: string;
|
|
56
|
-
dashboardName?: string;
|
|
57
|
-
columns?: FormattedColumn[];
|
|
58
|
-
dateField?: { table: string; field: string };
|
|
59
|
-
template?: boolean;
|
|
60
|
-
}
|
|
61
|
-
interface QuillQueryParams {
|
|
62
|
-
orgId: string;
|
|
63
|
-
metadata: QuillRequestMetadata;
|
|
64
|
-
environment?: string;
|
|
65
|
-
}
|
|
66
|
-
module.exports = ({
|
|
67
|
-
privateKey,
|
|
68
|
-
databaseConnectionString,
|
|
69
|
-
stagingDatabaseConnectionString,
|
|
70
|
-
}: QuillConfig) => {
|
|
71
|
-
const pool = new Pool({
|
|
72
|
-
connectionString: databaseConnectionString,
|
|
73
|
-
ssl: { rejectUnauthorized: false },
|
|
74
|
-
});
|
|
75
|
-
const stagingPool = new Pool({
|
|
76
|
-
connectionString: stagingDatabaseConnectionString,
|
|
77
|
-
});
|
|
78
|
-
return {
|
|
79
|
-
query: async ({ orgId, metadata, environment }: QuillQueryParams) => {
|
|
80
|
-
const targetPool = environment === "STAGING" ? stagingPool : pool;
|
|
81
|
-
const { task, query, id } = metadata;
|
|
82
|
-
|
|
83
|
-
if (task === "query") {
|
|
84
|
-
try {
|
|
85
|
-
const response = await axios.post(
|
|
86
|
-
"https://quill-344421.uc.r.appspot.com/validate",
|
|
87
|
-
{
|
|
88
|
-
query: query,
|
|
89
|
-
orgId: orgId,
|
|
90
|
-
filters: [],
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
headers: {
|
|
94
|
-
Authorization: `Bearer ${privateKey}`,
|
|
95
|
-
},
|
|
96
|
-
}
|
|
97
|
-
);
|
|
98
|
-
const { fieldToRemove } = response.data;
|
|
99
|
-
const queryResult = await targetPool.query(response.data.query);
|
|
100
|
-
return {
|
|
101
|
-
...queryResult,
|
|
102
|
-
fields: queryResult.fields.filter(
|
|
103
|
-
// @ts-ignore
|
|
104
|
-
(field) => field.name !== fieldToRemove
|
|
105
|
-
),
|
|
106
|
-
// @ts-ignore
|
|
107
|
-
rows: queryResult.rows.map((row) => {
|
|
108
|
-
delete row[fieldToRemove];
|
|
109
|
-
return row;
|
|
110
|
-
}),
|
|
111
|
-
};
|
|
112
|
-
} catch (err) {
|
|
113
|
-
return {
|
|
114
|
-
// @ts-ignore
|
|
115
|
-
...err,
|
|
116
|
-
// @ts-ignore
|
|
117
|
-
errorMessage: err && err.message ? err.message : "",
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
if (task === "config") {
|
|
122
|
-
try {
|
|
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
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
dashConfig = { ...dashConfig, filters: newFilters };
|
|
151
|
-
|
|
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
|
-
}
|
|
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
|
-
};
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
if (task === "create") {
|
|
176
|
-
try {
|
|
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
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
if (task === "item") {
|
|
202
|
-
try {
|
|
203
|
-
const { filters } = metadata;
|
|
204
|
-
const resp = await axios.get(
|
|
205
|
-
"https://quill-344421.uc.r.appspot.com/selfhostitem",
|
|
206
|
-
{
|
|
207
|
-
params: {
|
|
208
|
-
id,
|
|
209
|
-
orgId,
|
|
210
|
-
},
|
|
211
|
-
headers: {
|
|
212
|
-
Authorization: `Bearer ${privateKey}`,
|
|
213
|
-
},
|
|
214
|
-
}
|
|
215
|
-
);
|
|
216
|
-
let fieldToRemove: any, query;
|
|
217
|
-
|
|
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 {
|
|
226
|
-
const response = await axios.post(
|
|
227
|
-
"https://quill-344421.uc.r.appspot.com/validate",
|
|
228
|
-
{
|
|
229
|
-
dashboardItemId: id,
|
|
230
|
-
query: resp.data.queryString,
|
|
231
|
-
filters: filters,
|
|
232
|
-
orgId: orgId,
|
|
233
|
-
},
|
|
234
|
-
{
|
|
235
|
-
headers: {
|
|
236
|
-
Authorization: `Bearer ${privateKey}`,
|
|
237
|
-
},
|
|
238
|
-
}
|
|
239
|
-
);
|
|
240
|
-
|
|
241
|
-
({ fieldToRemove, query } = response.data);
|
|
242
|
-
|
|
243
|
-
const cacheKey = `config:${orgId}:${id}:${JSON.stringify(filters)}`;
|
|
244
|
-
setCache(cacheKey, { fieldToRemove, query });
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
const queryResult = await targetPool.query(query);
|
|
248
|
-
|
|
249
|
-
return {
|
|
250
|
-
...resp.data,
|
|
251
|
-
fields: queryResult.fields.filter(
|
|
252
|
-
// @ts-ignore
|
|
253
|
-
(field) => field.name !== fieldToRemove
|
|
254
|
-
),
|
|
255
|
-
// @ts-ignore
|
|
256
|
-
rows: queryResult.rows.map((row) => {
|
|
257
|
-
delete row[fieldToRemove];
|
|
258
|
-
return row;
|
|
259
|
-
}),
|
|
260
|
-
};
|
|
261
|
-
} catch (err) {
|
|
262
|
-
return {
|
|
263
|
-
// @ts-ignore
|
|
264
|
-
...err,
|
|
265
|
-
// @ts-ignore
|
|
266
|
-
errorMessage: err && err.message ? err.message : "",
|
|
267
|
-
};
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
},
|
|
271
|
-
};
|
|
272
|
-
};
|