@opengis/gis 0.2.193 → 0.2.195
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 +1 -1
- package/server/routes/map/functions/layerList.js +49 -38
- package/server/routes/registers/functions/getTableColumnMeta.js +23 -2
- package/server/routes/registers/functions/gis.suggest.js +17 -9
- package/server/routes/registers/registers.route.js +1 -0
- package/server/routes/registers/registers.schema.js +1 -0
package/package.json
CHANGED
|
@@ -5,13 +5,13 @@ import {
|
|
|
5
5
|
} from '@opengis/fastify-table/utils.js';
|
|
6
6
|
|
|
7
7
|
import getPermissions from '../../permissions/functions/get.permissions.js';
|
|
8
|
+
import gisSuggest from '../../registers/functions/gis.suggest.js';
|
|
8
9
|
|
|
9
10
|
const rclient = getRedis();
|
|
10
11
|
|
|
11
12
|
export default async function layerList({
|
|
12
13
|
sql, uid,
|
|
13
14
|
}, pg = pgClients.client) {
|
|
14
|
-
|
|
15
15
|
const layers = getTemplates('layer');
|
|
16
16
|
const files = Promise.all(layers.map(async (el) => {
|
|
17
17
|
const layer = await getTemplate('layer', el[0]);
|
|
@@ -40,40 +40,40 @@ export default async function layerList({
|
|
|
40
40
|
: (uid && !all_layers) ? '(s.is_public or s.cartocss_id = any($1))'
|
|
41
41
|
: 'is_public';
|
|
42
42
|
const q = `
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
43
|
+
select * from
|
|
44
|
+
(
|
|
45
|
+
select service_id as id, name, category, style, bbox::box2d as extent, st_asgeojson(bbox)::json as geom, coalesce('/api/vtile/'||service_id||'/ua/{z}/{x}/{y}.vmt',null) as url, coalesce(service_type, 'vtile') as service, group_id,
|
|
46
|
+
popup, card, filters, source_path, legend
|
|
47
|
+
from gis.services s where is_active and
|
|
48
|
+
${whereServices}
|
|
49
|
+
union all
|
|
50
|
+
select ogc_service_id as id, name, category, null as style, geom::box2d as extent, st_asgeojson(geom)::json as geom, url, 'ogc' as service, group_id,
|
|
51
|
+
null as popup, null as card, null as filters, table_name as source_path, null as legend
|
|
52
|
+
from gis.ogc_service s where enabled and
|
|
53
|
+
${whereOgcServices}
|
|
54
|
+
union all
|
|
55
|
+
select raster_id as id, name, null as category, null as style, geom::box2d as extent, st_asgeojson(geom)::json as geom,
|
|
56
|
+
coalesce('/api/gis-rtile/'||rtrim(
|
|
57
|
+
replace(
|
|
58
|
+
replace(
|
|
59
|
+
encode(source_path::bytea, 'base64'),
|
|
60
|
+
'+', '-'
|
|
61
|
+
),
|
|
62
|
+
'/', '_'
|
|
63
|
+
),
|
|
64
|
+
'='
|
|
65
|
+
)||'/{z}/{x}/{y}.png',null) as url, 'raster' as service, group_id,
|
|
66
|
+
null as popup, null as card, null as filters, source_path, null as legend
|
|
67
|
+
from gis.rasters s where is_active and
|
|
68
|
+
${whereRasters}
|
|
69
|
+
union all
|
|
70
|
+
select cartocss_id as id, name, null as category, style, geom::box2d as bbox, st_asgeojson(geom)::json as geom,
|
|
71
|
+
coalesce('/api/gis-rtile/'||cartocss_id||'/{z}/{x}/{y}.png',null) as url, 'cartocss' as service, group_id,
|
|
72
|
+
null as popup, null as card, null as filters, null as source_path, null as legend
|
|
73
|
+
from gis.cartocss s where enabled and
|
|
74
|
+
${whereCartocss}
|
|
75
|
+
)q order by q.name
|
|
76
|
+
`;
|
|
77
77
|
|
|
78
78
|
if (uid && sql) return q;
|
|
79
79
|
|
|
@@ -98,10 +98,9 @@ export default async function layerList({
|
|
|
98
98
|
const redisKey = `${pg?.options?.database}:gis-suggest-filter:${hash}`;
|
|
99
99
|
|
|
100
100
|
const cls = el.data ? await getSelect(el.data, pg) : undefined;
|
|
101
|
-
const { arr, sql } = cls || {};
|
|
102
101
|
|
|
103
102
|
const r = {
|
|
104
|
-
...el, id: el.name || el.id, type: el.type, api: `/api/gis-suggest/${hash}`,
|
|
103
|
+
...el, id: el.name || el.id, type: el.type, api: `/api/gis-suggest/${hash}`,
|
|
105
104
|
};
|
|
106
105
|
|
|
107
106
|
const unique = await rclient.setnx(redisKey, 1);
|
|
@@ -109,11 +108,22 @@ export default async function layerList({
|
|
|
109
108
|
|
|
110
109
|
// skip subsequent calls
|
|
111
110
|
if (!unique && ttl !== -1) {
|
|
111
|
+
const str = cls?.arr ? await rclient.get(`${redisKey}:options`) : undefined;
|
|
112
|
+
if (str && str.startsWith('[{') && str.endsWith('}]')) {
|
|
113
|
+
return { ...r, options: JSON.parse(str) };
|
|
114
|
+
}
|
|
112
115
|
return r;
|
|
113
116
|
}
|
|
114
117
|
|
|
115
118
|
await rclient.set(redisKey, JSON.stringify({ service: row.id, filter: el.name }), 'EX', 15 * 60);
|
|
116
|
-
|
|
119
|
+
|
|
120
|
+
const arr = cls?.arr?.length ? await gisSuggest({ token: hash, uid }, pg).then((r => r.data)) : undefined;
|
|
121
|
+
// const options = arr ? cls.arr.map(el => ({ ...el, count: arr.find(r => r.id === el.id)?.count || 0 })) : undefined;
|
|
122
|
+
if (arr) {
|
|
123
|
+
await rclient.set(`${redisKey}:options`, JSON.stringify(arr), 'EX', 15 * 60);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return { ...r, options: arr };
|
|
117
127
|
}));
|
|
118
128
|
row.filters = filters;
|
|
119
129
|
}));
|
|
@@ -130,4 +140,5 @@ export default async function layerList({
|
|
|
130
140
|
// return files;
|
|
131
141
|
|
|
132
142
|
return rows.concat(files);
|
|
143
|
+
|
|
133
144
|
}
|
|
@@ -83,6 +83,25 @@ export default async function getTableColumnMeta(
|
|
|
83
83
|
? `id in ( with cc(id, text) as (${select}) select id from cc where (left(lower("text"),${key.length})=$1) )`
|
|
84
84
|
: `id in ( with cc(id, text) as (${select}) select id from cc where (lower("text") ~ $1) )`;
|
|
85
85
|
|
|
86
|
+
const countQuery = pg.pgType?.[dataTypeID]?.includes("[]")
|
|
87
|
+
? `select count(distinct id::text)::int from ( select unnest("${queryColumn.replace(
|
|
88
|
+
/"/g,
|
|
89
|
+
""
|
|
90
|
+
)}"::text[]) as id from ${tableName})q where ${arr?.length ? 'id::text=any($1::text[])' : '1=1'}`
|
|
91
|
+
: `select count(distinct "${queryColumn.replace(
|
|
92
|
+
/"/g,
|
|
93
|
+
""
|
|
94
|
+
)}"::text)::int from ${tableName} where ${arr?.length ? `"${queryColumn.replace(
|
|
95
|
+
/"/g,
|
|
96
|
+
""
|
|
97
|
+
)}"::text=any($1::text[])` : '1=1'}`;
|
|
98
|
+
|
|
99
|
+
const total = arr?.length ? await pg
|
|
100
|
+
.query(countQuery, [arr.map((el) => el.id)])
|
|
101
|
+
.then((r) => r.rows?.[0]?.count || 0) : await pg
|
|
102
|
+
.query(countQuery)
|
|
103
|
+
.then((r) => r.rows?.[0]?.count || 0);
|
|
104
|
+
|
|
86
105
|
if (pg.pgType?.[dataTypeID]?.includes("[]")) {
|
|
87
106
|
const original = filtered
|
|
88
107
|
? `with c(id,text) as (select id, id as text from (select unnest("${queryColumn.replace(
|
|
@@ -96,7 +115,8 @@ export default async function getTableColumnMeta(
|
|
|
96
115
|
|
|
97
116
|
return {
|
|
98
117
|
arr,
|
|
99
|
-
original,
|
|
118
|
+
original: select ? `with c(id,text) as (${select}) select id, text from c` : original,
|
|
119
|
+
total,
|
|
100
120
|
searchQuery: select ? searchQuerySelect : searchQueryDefault,
|
|
101
121
|
pk: "id",
|
|
102
122
|
};
|
|
@@ -120,7 +140,8 @@ export default async function getTableColumnMeta(
|
|
|
120
140
|
|
|
121
141
|
return {
|
|
122
142
|
arr,
|
|
123
|
-
original,
|
|
143
|
+
original: select ? `with c(id,text) as (${select}) select id, text from c` : original,
|
|
144
|
+
total,
|
|
124
145
|
searchQuery: select ? searchQuerySelect : searchQueryDefault,
|
|
125
146
|
pk: "id",
|
|
126
147
|
};
|
|
@@ -8,7 +8,7 @@ const rclient = getRedis();
|
|
|
8
8
|
const count = false;
|
|
9
9
|
const maxLimit = 100;
|
|
10
10
|
|
|
11
|
-
export default async function gisSuggest({ token, key, val, uid, lang = 'ua', limit: limit1 = 50 }, pg) {
|
|
11
|
+
export default async function gisSuggest({ token, key, val, uid, lang = 'ua', limit: limit1 = 50, offset: offset1 = 0 }, pg) {
|
|
12
12
|
const time = Date.now();
|
|
13
13
|
|
|
14
14
|
// GET /api/gis-registry/:id or GET /api/gis-service/:id
|
|
@@ -71,6 +71,7 @@ export default async function gisSuggest({ token, key, val, uid, lang = 'ua', li
|
|
|
71
71
|
const { arr, searchQuery } = clsMeta;
|
|
72
72
|
|
|
73
73
|
const limit = Math.min(limit1 || maxLimit, maxLimit);
|
|
74
|
+
const offset = offset1 === 0 ? offset1 : Math.min(offset1 || maxLimit, maxLimit);
|
|
74
75
|
|
|
75
76
|
const [schemaName, tableName] = registry.table_name.split('.');
|
|
76
77
|
|
|
@@ -120,7 +121,7 @@ export default async function gisSuggest({ token, key, val, uid, lang = 'ua', li
|
|
|
120
121
|
: el.id && vals.includes(el.id.toString())
|
|
121
122
|
);
|
|
122
123
|
|
|
123
|
-
const data = data2.slice(
|
|
124
|
+
const data = data2.slice(offset, offset + limit);
|
|
124
125
|
|
|
125
126
|
if (data.length && count) {
|
|
126
127
|
const counts = qRes.rows?.reduce?.(
|
|
@@ -138,6 +139,7 @@ export default async function gisSuggest({ token, key, val, uid, lang = 'ua', li
|
|
|
138
139
|
return {
|
|
139
140
|
time: Date.now() - time,
|
|
140
141
|
limit,
|
|
142
|
+
offset,
|
|
141
143
|
count: data.length,
|
|
142
144
|
total: arr.length,
|
|
143
145
|
mode: "array",
|
|
@@ -176,6 +178,7 @@ export default async function gisSuggest({ token, key, val, uid, lang = 'ua', li
|
|
|
176
178
|
const whereQuery = where.filter(Boolean).join(" and ") || "true";
|
|
177
179
|
|
|
178
180
|
args.push(limit);
|
|
181
|
+
args.push(offset || 0);
|
|
179
182
|
|
|
180
183
|
let sqlSuggest = !cls
|
|
181
184
|
? `${clsMeta.original}
|
|
@@ -187,8 +190,8 @@ export default async function gisSuggest({ token, key, val, uid, lang = 'ua', li
|
|
|
187
190
|
? `c.text = ANY(o."${name}"::text)`
|
|
188
191
|
: `o."${name}"::text IS NOT DISTINCT FROM c.text`
|
|
189
192
|
} ) and ${whereQuery || "true"}
|
|
190
|
-
${order} LIMIT $${args.length}::bigint`
|
|
191
|
-
: `with c(id,text) as ( ${clsMeta.original} where ${whereQuery} ${order}) select * from c LIMIT $${args.length}::bigint`;
|
|
193
|
+
${order} LIMIT $${args.length - 1}::bigint OFFSET $${args.length}::bigint`
|
|
194
|
+
: `with c(id,text) as ( ${clsMeta.original} where ${whereQuery} ${order}) select * from c LIMIT $${args.length - 1}::bigint OFFSET $${args.length}::bigint`;
|
|
192
195
|
|
|
193
196
|
if (sqlSuggest.includes("{{parent}}")) {
|
|
194
197
|
args.push(parent || "");
|
|
@@ -204,6 +207,8 @@ export default async function gisSuggest({ token, key, val, uid, lang = 'ua', li
|
|
|
204
207
|
.query(sqlSuggest, args)
|
|
205
208
|
.then((r) => r.rows || []);
|
|
206
209
|
|
|
210
|
+
const total = clsMeta.total ?? arr.length;
|
|
211
|
+
|
|
207
212
|
// in case id / text = Boolean
|
|
208
213
|
const data = dataNew.filter(
|
|
209
214
|
(el) => Object.hasOwn(el, "id") && Object.hasOwn(el, "text")
|
|
@@ -230,16 +235,18 @@ export default async function gisSuggest({ token, key, val, uid, lang = 'ua', li
|
|
|
230
235
|
)
|
|
231
236
|
?.filter((el) => !val || val?.split?.(",")?.includes?.(el.id))
|
|
232
237
|
: arr;
|
|
233
|
-
const data2 = data1.filter((el) => ids.includes(el.id))
|
|
238
|
+
const data2 = data1.filter((el) => ids.includes(el.id));
|
|
234
239
|
data2.forEach((el) => Object.assign(el, { count: data.find((e) => e.text === el.id)?.count || 0 }));
|
|
235
|
-
if (data.find((el) => el.id === 'null') && !data2.find((el) => el.id === 'null')) {
|
|
240
|
+
if (data.find((el) => el.id === 'null') && !data2.find((el) => el.id === 'null') && limit > data2.length) {
|
|
236
241
|
data2.push(data.find((el) => el.id === 'null'));
|
|
237
242
|
}
|
|
243
|
+
|
|
238
244
|
return {
|
|
239
245
|
time: Date.now() - time,
|
|
240
246
|
limit,
|
|
247
|
+
offset,
|
|
241
248
|
count: data2.length,
|
|
242
|
-
total
|
|
249
|
+
total,
|
|
243
250
|
mode: "array",
|
|
244
251
|
data: data2,
|
|
245
252
|
};
|
|
@@ -263,8 +270,9 @@ export default async function gisSuggest({ token, key, val, uid, lang = 'ua', li
|
|
|
263
270
|
return {
|
|
264
271
|
time: Date.now() - time,
|
|
265
272
|
limit,
|
|
273
|
+
offset,
|
|
266
274
|
count: data.length,
|
|
267
|
-
total: clsMeta.
|
|
275
|
+
total: clsMeta.total - 0,
|
|
268
276
|
mode: type === "cls" ? "array" : "sql",
|
|
269
277
|
db: clsMeta.db,
|
|
270
278
|
sql: process.platform === 'win32' ? sqlSuggest : undefined,
|
|
@@ -290,7 +298,7 @@ export default async function gisSuggest({ token, key, val, uid, lang = 'ua', li
|
|
|
290
298
|
time: Date.now() - time,
|
|
291
299
|
limit,
|
|
292
300
|
count: data.length,
|
|
293
|
-
total: clsMeta.
|
|
301
|
+
total: clsMeta.total - 0,
|
|
294
302
|
mode: "sql",
|
|
295
303
|
sql: process.platform === 'win32' ? sqlSuggest : undefined,
|
|
296
304
|
data,
|