@opengis/gis 0.2.189 → 0.2.190

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/gis",
3
- "version": "0.2.189",
3
+ "version": "0.2.190",
4
4
  "type": "module",
5
5
  "author": "Softpro",
6
6
  "main": "./dist/index.js",
@@ -1,9 +1,13 @@
1
+ import { createHash } from 'node:crypto';
2
+
1
3
  import {
2
- pgClients, yml2json, getTemplates, getTemplate,
4
+ pgClients, yml2json, getTemplates, getTemplate, getSelect, getRedis
3
5
  } from '@opengis/fastify-table/utils.js';
4
6
 
5
7
  import getPermissions from '../../permissions/functions/get.permissions.js';
6
8
 
9
+ const rclient = getRedis();
10
+
7
11
  export default async function layerList({
8
12
  sql, uid,
9
13
  }, pg = pgClients.client) {
@@ -87,6 +91,33 @@ export default async function layerList({
87
91
  return [];
88
92
  }
89
93
 
94
+ await Promise.all(rows.filter((row) => row.filters && row.source_path).map(async (row) => {
95
+ const filters = await Promise.all((row.filters || []).filter((f) => f.disabled !== true).map(async (el) => {
96
+
97
+ const hash = createHash('md5').update([row.id, el.name, el.data].filter(Boolean).join('-')).digest('hex');
98
+ const redisKey = `${pg?.options?.database}:gis-suggest-filter:${hash}`;
99
+
100
+ const cls = el.data ? await getSelect(el.data, pg) : undefined;
101
+ const { arr, sql } = cls || {};
102
+
103
+ const r = {
104
+ ...el, id: el.name || el.id, type: el.type, api: `/api/gis-suggest/${hash}`, options: arr, select: sql
105
+ };
106
+
107
+ const unique = await rclient.setnx(redisKey, 1);
108
+ const ttl = await rclient.ttl(redisKey);
109
+
110
+ // skip subsequent calls
111
+ if (!unique && ttl !== -1) {
112
+ return r;
113
+ }
114
+
115
+ await rclient.set(redisKey, JSON.stringify({ service: row.id, filter: el.name }), 'EX', 15 * 60);
116
+ return r;
117
+ }));
118
+ row.filters = filters;
119
+ }));
120
+
90
121
  // parse service style
91
122
  rows.forEach(row => Object.assign(row, { style: row.style && ['vtile', 'geojson'].includes(row.service) ? yml2json(row.style) : row.style }));
92
123
  // parse extent string to number[]