@opengis/fastify-table 1.0.88 → 1.0.89

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/Changelog.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # fastify-table
2
2
 
3
- ## 1.0.88 - 26.08.2024
3
+ ## 1.0.89 - 26.08.2024
4
4
 
5
5
  - data API meta bbox polyline support
6
6
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "1.0.88",
3
+ "version": "1.0.89",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "main": "index.js",
@@ -9,7 +9,7 @@
9
9
  "test": "node --test"
10
10
  },
11
11
  "dependencies": {
12
- "@opengis/fastify-hb": "^1.0.0",
12
+ "@opengis/fastify-hb": "^1.1.0",
13
13
  "@fastify/sensible": "^5.0.0",
14
14
  "@fastify/url-data": "^5.4.0",
15
15
  "fastify": "^4.26.1",
@@ -60,7 +60,7 @@ export default async function dataAPI({
60
60
  const custom = loadTable.filterCustom && query.custom ? loadTable.filterCustom[query.custom]?.sql : null;
61
61
  const search = loadTable.meta?.search && query.search ? `(${loadTable.meta?.search.split(',').map(el => `${el} ilike '%${query.search}%'`).join(' or ')})` : null;
62
62
  const queryBbox = query?.bbox ? query.bbox.replace(/ /g, ',').split(',')?.map((el) => el - 0) : [];
63
- const queryPolyline = meta?.bbox && query?.polyline ? `ST_Contains(ST_MakePolygon(ST_LineFromEncodedPolyline($1)),${meta.bbox})` : undefined;
63
+ const queryPolyline = meta?.bbox && query?.polyline ? `ST_Contains(ST_MakePolygon(ST_LineFromEncodedPolyline('${query?.polyline}')),${meta.bbox})` : undefined;
64
64
  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;
65
65
 
66
66
  const access = await getAccess(req, params.table);
@@ -70,9 +70,9 @@ export default async function dataAPI({
70
70
 
71
71
  if (query.sql === '1') { return q; }
72
72
 
73
- const { rows } = await pg.query(q, (opt?.id || params.id ? [opt?.id || params.id] : null) || (query.key && loadTable.key ? [query.key] : null) || (query?.polyline ? [query?.polyline] : []));
73
+ const { rows } = await pg.query(q, (opt?.id || params.id ? [opt?.id || params.id] : null) || (query.key && loadTable.key ? [query.key] : []));
74
74
 
75
- const total = keyQuery || opt?.id || params.id ? rows.length : await pg.queryCache(`select count(*) from ${table} t ${sqlTable} where ${where.filter((el) => !el.includes('$1')).join(' and ') || 'true'}`).then((el) => el?.rows[0]?.count);
75
+ const total = keyQuery || opt?.id || params.id ? rows.length : await pg.queryCache(`select count(*) from ${table} t ${sqlTable} where ${where.join(' and ') || 'true'}`).then((el) => (el?.rows[0]?.count || 0) - 0);
76
76
 
77
77
  await metaFormat({ rows, table: params.table });
78
78
  const res = {