@opengis/fastify-table 1.3.31 → 1.3.33
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/package.json
CHANGED
|
@@ -72,6 +72,11 @@ async function init(client) {
|
|
|
72
72
|
const { table, args = [], time = 15 } = param;
|
|
73
73
|
const seconds = typeof time !== 'number' || time < 0 ? 0 : time * 60;
|
|
74
74
|
|
|
75
|
+
if (seconds === 0 || config.disableCache) {
|
|
76
|
+
const data = await query(q, args || []);
|
|
77
|
+
return data;
|
|
78
|
+
}
|
|
79
|
+
|
|
75
80
|
// CRUD table state
|
|
76
81
|
const keyCacheTable = `pg:${table}:crud`;
|
|
77
82
|
const crudInc = table ? await rclient.get(keyCacheTable) || 0 : 0;
|
|
@@ -22,6 +22,8 @@ export default async function dataAPI(req, reply, called) {
|
|
|
22
22
|
const timeArr = [Date.now()];
|
|
23
23
|
const { uid } = user;
|
|
24
24
|
|
|
25
|
+
const checkQuery = (item) => (user?.user_type === 'superadmin' ? !item.includes('{{uid}}') : true);
|
|
26
|
+
|
|
25
27
|
const hookData = await applyHook('preData', {
|
|
26
28
|
pg, table: params?.table, id: params?.id, user,
|
|
27
29
|
});
|
|
@@ -136,7 +138,7 @@ export default async function dataAPI(req, reply, called) {
|
|
|
136
138
|
const bbox = meta?.bbox && queryBbox.filter((el) => !Number.isNaN(el))?.length === 4 ? `${meta.bbox} && 'box(${queryBbox[0]} ${queryBbox[1]},${queryBbox[2]} ${queryBbox[3]})'::box2d ` : undefined;
|
|
137
139
|
|
|
138
140
|
const interfaceQuery = params?.query ? await handlebars.compile(params?.query)({ user, uid }) : undefined;
|
|
139
|
-
const where = [(tokenData?.id || hookData?.id || params.id ? ` "${pk}" = $1` : null), keyQuery, loadTable?.query, tokenData?.query, fData.q, search, accessQuery || '1=1', contextQuery, bbox, queryPolyline, interfaceQuery].filter((el) => el).filter((el) => (
|
|
141
|
+
const where = [(tokenData?.id || hookData?.id || params.id ? ` "${pk}" = $1` : null), keyQuery, loadTable?.query, tokenData?.query, fData.q, search, accessQuery || '1=1', contextQuery, bbox, queryPolyline, interfaceQuery].filter((el) => el).filter((el) => checkQuery(el));
|
|
140
142
|
|
|
141
143
|
// const cardColumns = cardSqlFiltered.length ? `,${cardSqlFiltered.map((el) => el.name)}` : '';
|
|
142
144
|
const q = `select ${pk ? `"${pk}" as id,` : ''}
|
|
@@ -169,7 +171,7 @@ export default async function dataAPI(req, reply, called) {
|
|
|
169
171
|
});
|
|
170
172
|
}
|
|
171
173
|
|
|
172
|
-
const filterWhere = [fData.q, search, bbox, queryPolyline, interfaceQuery, loadTable?.query, tokenData?.query].filter((el) => el);
|
|
174
|
+
const filterWhere = [fData.q, search, bbox, queryPolyline, interfaceQuery, loadTable?.query, tokenData?.query].filter((el) => el).filter((el) => checkQuery(el));
|
|
173
175
|
|
|
174
176
|
const aggColumns = columns.filter((el) => el.agg).reduce((acc, curr) => Object.assign(acc, { [curr.name]: curr.agg }), {});
|
|
175
177
|
const aggregates = dbColumns.map((el) => ({ name: el.name, type: pg.pgType?.[el.dataTypeID] })).filter((el) => ['numeric', 'double precision'].includes(el.type) && aggColumns[el.name]);
|
|
@@ -178,14 +180,14 @@ export default async function dataAPI(req, reply, called) {
|
|
|
178
180
|
count(*) FILTER(WHERE ${filterWhere.join(' and ') || 'true'})::int as filtered
|
|
179
181
|
${aggregates.length ? `,${aggregates.map((el) => `${aggColumns[el.name]}(${el.name}) FILTER(WHERE ${filterWhere.join(' and ') || 'true'}) as ${el.name}`).join(',')}` : ''}
|
|
180
182
|
from (select * ${sql?.filter(el => el.inline).map(el => `,(${el.sql})`).join('') || ''} from ${table} t ${sqlTable})q
|
|
181
|
-
where ${[loadTable?.query, tokenData?.query, accessQuery, contextQuery].filter(el => el).join(' and ') || 'true'} `
|
|
183
|
+
where ${[loadTable?.query, tokenData?.query, accessQuery, contextQuery].filter(el => el).filter((el) => checkQuery(el)).join(' and ') || 'true'} `
|
|
182
184
|
.replace(/{{uid}}/g, uid);
|
|
183
185
|
|
|
184
186
|
if (query.sql === '2') { return qCount; }
|
|
185
187
|
|
|
186
188
|
const counts = keyQuery || tokenData?.id || hookData?.id || params.id
|
|
187
189
|
? { total: rows.length, filtered: rows.length }
|
|
188
|
-
: await pg.queryCache?.(qCount, { table: loadTable?.table || tokenData?.table, time: 5
|
|
190
|
+
: await pg.queryCache?.(qCount, { table: loadTable?.table || tokenData?.table, time: 5 }).then(el => el?.rows[0] || {});
|
|
189
191
|
|
|
190
192
|
timeArr.push(Date.now())
|
|
191
193
|
const { total, filtered } = counts || {};
|