@opengis/gis 0.2.174 → 0.2.176

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.
Files changed (158) hide show
  1. package/README.md +181 -181
  2. package/dist/{CardIcon-Cg8bUM4G.js → CardIcon-c1Q2M3wQ.js} +1 -1
  3. package/dist/{EntityTablePage-DHQGlLRk.js → EntityTablePage-B5gpkH4S.js} +2 -2
  4. package/dist/{ExtentOutlineLayer.vue_vue_type_script_setup_true_lang-BIL1ocLY.js → ExtentOutlineLayer.vue_vue_type_script_setup_true_lang-DnGSvmMU.js} +1 -1
  5. package/dist/{HeaderActions.vue_vue_type_script_setup_true_lang-Buff9gTO.js → HeaderActions.vue_vue_type_script_setup_true_lang-C2B61JP6.js} +1 -1
  6. package/dist/{MapSettings-De-z7r5t.js → MapSettings-6-Xru5Q8.js} +2 -2
  7. package/dist/{RastersTablePage-Cdgkri9K.js → RastersTablePage-CXNOcTy-.js} +2 -2
  8. package/dist/{cartocss-BT50SVhy.js → cartocss-BFVqWvfP.js} +6 -6
  9. package/dist/{import-utils-CMWiuRPp.js → import-utils-uxk4LdUJ.js} +1 -1
  10. package/dist/{index-CHFLgCGW.js → index-CahlV-Xs.js} +39 -39
  11. package/dist/index.css +1 -1
  12. package/dist/index.js +1 -1
  13. package/dist/index.umd.cjs +19 -19
  14. package/dist/{raster-dSEb1SIG.js → raster-CEi56f0P.js} +3 -3
  15. package/dist/{register-D7Puupgo.js → register-NFAGBNa3.js} +3 -3
  16. package/dist/{service-Cz6T0O3Z.js → service-BYspag8U.js} +829 -832
  17. package/dist/{vs-datatable-DqVncrSg.js → vs-datatable-CHcBr6zy.js} +2 -2
  18. package/module/gis/cls/service_type.json +42 -42
  19. package/module/gis/form/gis.registers.form.json +4 -1
  20. package/module/test/map/addr.json +302 -302
  21. package/module/test/map/addr1.yml +23 -23
  22. package/module/test/select/address.str_id.sql +3 -3
  23. package/package.json +77 -77
  24. package/plugin.js +64 -64
  25. package/server/migrations/array_intersect.sql +13 -13
  26. package/server/migrations/cartocss.sql +27 -27
  27. package/server/migrations/group_list.sql +74 -74
  28. package/server/migrations/maps.sql +30 -30
  29. package/server/migrations/metadata.sql +415 -415
  30. package/server/migrations/ogc.sql +106 -106
  31. package/server/migrations/rasters.sql +265 -265
  32. package/server/migrations/services.sql +247 -247
  33. package/server/migrations/services_users_rel.sql +22 -22
  34. package/server/migrations/widgets.sql +20 -20
  35. package/server/plugins/crons.js +21 -21
  36. package/server/plugins/mapnik/funcs/checkRasterFile.js +107 -107
  37. package/server/plugins/mapnik/funcs/mapnik.js +151 -151
  38. package/server/plugins/mapnik/funcs/rootFolder.mjs +8 -8
  39. package/server/plugins/mapnik/map.proto +437 -437
  40. package/server/plugins/vite.js +74 -74
  41. package/server/routes/cartocss/cartocss.route.js +31 -31
  42. package/server/routes/cartocss/cartocss.route.test.js +78 -78
  43. package/server/routes/cartocss/cartocss.schema.js +73 -73
  44. package/server/routes/cartocss/functions/add.cartocss.js +39 -39
  45. package/server/routes/cartocss/functions/get.cartocss.js +57 -57
  46. package/server/routes/gis/functions/checkXML.js +107 -107
  47. package/server/routes/gis/functions/dashboard.js +24 -24
  48. package/server/routes/gis/gis.route.js +26 -26
  49. package/server/routes/gis/gis.route.test.js +33 -33
  50. package/server/routes/map/functions/clearTiles.js +35 -35
  51. package/server/routes/map/functions/geojson.js +187 -187
  52. package/server/routes/map/functions/gis.convert.js +65 -65
  53. package/server/routes/map/functions/gis.icon.js +220 -220
  54. package/server/routes/map/functions/jsonData.js +206 -206
  55. package/server/routes/map/functions/layerList.js +102 -102
  56. package/server/routes/map/functions/map.js +122 -122
  57. package/server/routes/map/functions/mapCatalog.js +72 -72
  58. package/server/routes/map/functions/mapCatalogAttribute.js +53 -53
  59. package/server/routes/map/functions/mapFeatures.js +133 -133
  60. package/server/routes/map/functions/mapFormat.js +232 -231
  61. package/server/routes/map/functions/mapTiles.js +162 -162
  62. package/server/routes/map/functions/maps.js +15 -15
  63. package/server/routes/map/functions/marker_icon.js +43 -43
  64. package/server/routes/map/functions/parseGeoFile.js +85 -85
  65. package/server/routes/map/functions/pointHeight.js +51 -51
  66. package/server/routes/map/functions/vtile.js +174 -174
  67. package/server/routes/map/functions/vtile1.js +185 -185
  68. package/server/routes/map/map.route.js +280 -280
  69. package/server/routes/map/map.route.test.js +503 -503
  70. package/server/routes/map/map.schema.js +356 -356
  71. package/server/routes/map/pin/circle1.svg +76 -76
  72. package/server/routes/map/pin/circle2.svg +18 -18
  73. package/server/routes/map/pin/none.svg +12 -12
  74. package/server/routes/map/pin/pin.svg +14 -14
  75. package/server/routes/map/pin/pin1.svg +16 -16
  76. package/server/routes/map/pin/pin2.svg +7 -7
  77. package/server/routes/map/pin/pin3.svg +34 -34
  78. package/server/routes/map/pin/pin4.svg +14 -14
  79. package/server/routes/map/pin/pin5.svg +7 -7
  80. package/server/routes/map/pin/pin6.svg +12 -12
  81. package/server/routes/map/pin/pin7.svg +12 -12
  82. package/server/routes/mapnik/functions/cartoBounds.js +32 -32
  83. package/server/routes/mapnik/functions/clearTiles.js +103 -103
  84. package/server/routes/mapnik/functions/convertBoundToTile.js +27 -27
  85. package/server/routes/mapnik/functions/createXml.js +76 -76
  86. package/server/routes/mapnik/functions/createXmlMulti.js +72 -72
  87. package/server/routes/mapnik/functions/fileSearch.js +35 -35
  88. package/server/routes/mapnik/functions/fileStat.js +28 -28
  89. package/server/routes/mapnik/functions/pretile.js +138 -138
  90. package/server/routes/mapnik/functions/rasterInfo.js +66 -66
  91. package/server/routes/mapnik/functions/readDir.js +22 -22
  92. package/server/routes/mapnik/functions/rtile.js +164 -164
  93. package/server/routes/mapnik/functions/uploadRaster.js +152 -152
  94. package/server/routes/mapnik/functions/uploadXML.js +140 -140
  95. package/server/routes/mapnik/mapnik.route.js +102 -102
  96. package/server/routes/mapnik/mapnik.route.test.js +370 -370
  97. package/server/routes/mapnik/mapnik.schema.mjs +195 -195
  98. package/server/routes/mapnik.prefixless/functions/mapnikLogger.js +31 -31
  99. package/server/routes/mapnik.prefixless/functions/mapnikStat.js +21 -21
  100. package/server/routes/mapnik.prefixless/mapnik.prefixless.route.js +20 -20
  101. package/server/routes/mapnik.prefixless/mapnik.prefixless.route.test.js +91 -91
  102. package/server/routes/mapnik.prefixless/mapnik.prefixless.schema.mjs +27 -27
  103. package/server/routes/maps/functions/add.map.js +42 -42
  104. package/server/routes/maps/functions/del.map.js +17 -17
  105. package/server/routes/maps/functions/get.map.js +119 -119
  106. package/server/routes/maps/maps.route.js +58 -58
  107. package/server/routes/maps/maps.route.test.js +231 -231
  108. package/server/routes/maps/maps.schema.js +9 -9
  109. package/server/routes/metadata/functions/editMetadata.js +35 -35
  110. package/server/routes/metadata/functions/metadataXML.js +19 -19
  111. package/server/routes/metadata/metadata.route.js +26 -26
  112. package/server/routes/metadata/metadata.route.test.js +46 -46
  113. package/server/routes/metadata/metadata.schema.js +53 -53
  114. package/server/routes/ogc/functions/map.info.point.js +117 -117
  115. package/server/routes/ogc/ogc.route.js +21 -21
  116. package/server/routes/ogc/ogc.route.test.js +53 -53
  117. package/server/routes/ogc/ogc.schema.js +16 -16
  118. package/server/routes/permissions/functions/catalog.permissions.edit.js +20 -20
  119. package/server/routes/permissions/functions/catalog.permissions.js +12 -12
  120. package/server/routes/permissions/functions/get.permissions.js +59 -59
  121. package/server/routes/permissions/functions/gis.catalog.js +80 -80
  122. package/server/routes/permissions/permissions.route.js +35 -35
  123. package/server/routes/permissions/permissions.route.test.js +35 -35
  124. package/server/routes/permissions/permissions.schema.js +43 -43
  125. package/server/routes/registers/functions/add.registry.js +37 -37
  126. package/server/routes/registers/functions/classifiers.js +100 -100
  127. package/server/routes/registers/functions/columns.js +3 -3
  128. package/server/routes/registers/functions/content.type.js +9 -9
  129. package/server/routes/registers/functions/del.registry.js +14 -14
  130. package/server/routes/registers/functions/get.info.js +93 -93
  131. package/server/routes/registers/functions/gis.export.js +159 -159
  132. package/server/routes/registers/functions/gis.registry.js +71 -71
  133. package/server/routes/registers/functions/gis.registry.list.js +61 -61
  134. package/server/routes/registers/functions/handleRegistryRequest.js +147 -147
  135. package/server/routes/registers/functions/map.registry.js +87 -87
  136. package/server/routes/registers/registers.route.js +80 -80
  137. package/server/routes/registers/registers.route.test.js +144 -144
  138. package/server/routes/registers/registers.schema.js +246 -246
  139. package/server/routes/root.mjs +3 -3
  140. package/server/routes/services/functions/add.service.js +62 -62
  141. package/server/routes/services/functions/create.route.js +93 -93
  142. package/server/routes/services/functions/del.service.js +12 -12
  143. package/server/routes/services/functions/get.layer.geom.js +27 -27
  144. package/server/routes/services/functions/get.service.users.js +76 -76
  145. package/server/routes/services/functions/get.services.col.js +34 -34
  146. package/server/routes/services/functions/get.services.js +89 -89
  147. package/server/routes/services/functions/legend.auto.js +77 -77
  148. package/server/routes/services/services.route.js +76 -76
  149. package/server/routes/services/services.route.test.js +167 -167
  150. package/server/routes/services/services.schema.js +278 -278
  151. package/server/routes/widgets/functions/add.widget.js +38 -38
  152. package/server/routes/widgets/functions/del.widget.js +17 -17
  153. package/server/routes/widgets/functions/get.widget.js +41 -41
  154. package/server/routes/widgets/widgets.route.js +61 -61
  155. package/server/routes/widgets/widgets.route.test.js +144 -144
  156. package/server/routes/widgets/widgets.schema.js +24 -24
  157. package/server/shared/listFiles.js +15 -0
  158. package/utils.js +13 -13
@@ -1,206 +1,206 @@
1
- import path from 'node:path';
2
- import { existsSync } from 'node:fs';
3
- import { createHash } from 'node:crypto';
4
- import {
5
- readFile, stat, mkdir, writeFile,
6
- } from 'node:fs/promises';
7
-
8
- import {
9
- pgClients, getMeta, metaFormat,
10
- } from '@opengis/fastify-table/utils.js';
11
-
12
- import rootFolder from '../../../plugins/mapnik/funcs/rootFolder.mjs';
13
- import { BadRequestError, NotFoundError } from '@opengis/fastify-table/errors.js';
14
-
15
- const systemColumns = ['uid', 'cdate', 'editor_id', 'editor_date', 'created_by', 'created_at', 'updated_by', 'updated_at', 'geom'];
16
-
17
- const unittest = process.env.NODE_ENV === 'test' || process.env.VITEST;
18
-
19
- /**
20
- * Повертає JSON дані для реєстру на основі налаштувань з gis.registers
21
- *
22
- * @method GET
23
- * @param {string} params.layer - register_id
24
- * @param {string} query.page - номер сторінки (default: 1)
25
- * @param {string} query.limit - кількість записів на сторінку (default: 100)
26
- * @param {string} query.where - додаткова WHERE умова
27
- * @param {string} query.sql - повернути SQL запит замість даних
28
- * @param {boolean} query.nocache - не використовувати кеш
29
- */
30
- export default async function jsonData({
31
- layer,
32
- page = 1,
33
- limit = 100,
34
- // where,
35
- sql,
36
- nocache
37
- }, pg = pgClients.client) {
38
- if (!layer) {
39
- throw BadRequestError('not enough params: layer (register_id)');
40
- }
41
-
42
- const registerId = layer.replace('.json', '');
43
- const pageNum = parseInt(page, 10) || 1;
44
- const limitNum = Math.min(parseInt(limit, 10) || 100, 1000); // max 1000
45
- const offset = (pageNum - 1) * limitNum;
46
-
47
- if (!pg.pk?.['gis.registers']) {
48
- throw NotFoundError('registers table not found');
49
- }
50
-
51
- const register = await pg.query(
52
- `select
53
- table_name,
54
- pk,
55
- query,
56
- columns,
57
- is_public,
58
- is_active,
59
- "order"
60
- from gis.registers
61
- where register_id = $1 and is_active = true and is_public = true`,
62
- [registerId],
63
- ).then(r => r.rows?.[0]);
64
-
65
- if (!register) {
66
- throw NotFoundError('register not found or not available');
67
- }
68
-
69
- const {
70
- table_name: table,
71
- pk,
72
- query: registerQuery,
73
- columns,
74
- order: orderBy,
75
- } = register;
76
-
77
- if (!table) {
78
- throw BadRequestError('invalid register table_name');
79
- }
80
-
81
- if (!pg.pk?.[table]?.length) {
82
- throw NotFoundError('table not found');
83
- }
84
-
85
- const meta = await getMeta({ pg, table });
86
- const { columns: metaColumns = [] } = meta || {};
87
-
88
- let attributeColumns = [];
89
- if (columns && Array.isArray(columns)) {
90
- attributeColumns = columns
91
- .filter(col => col.name && !systemColumns.includes(col.name))
92
- .map(col => col.name);
93
- }
94
-
95
- const columnsFiltered = attributeColumns.length > 0
96
- ? metaColumns.filter(col => attributeColumns.includes(col.name) && !systemColumns.includes(col.name))
97
- : metaColumns.filter(col => !systemColumns.includes(col.name));
98
-
99
- const props = columnsFiltered.map(el =>
100
- `"${el.name}"${['int4'].includes(el.type) ? '::text' : ''}`
101
- ).join(', ');
102
-
103
- if (!props) {
104
- throw BadRequestError('no columns to select');
105
- }
106
-
107
- const cacheHash = createHash('md5')
108
- .update([registerId, /*where,*/ registerQuery, pageNum, limitNum].filter(el => el).join('-'))
109
- .digest('hex');
110
-
111
- const today = new Date().toISOString().split('T')[0];
112
- const filepath = path.join(
113
- rootFolder,
114
- `/json/${registerId}/${today}/${cacheHash}.json`,
115
- );
116
-
117
- if (existsSync(filepath) && !nocache && !sql && !unittest) {
118
- const { birthtimeMs = Date.now() } = await stat(filepath);
119
- const ageInMs = Date.now() - birthtimeMs;
120
- if (ageInMs < 86400000) {
121
- const content = await readFile(filepath, 'utf8');
122
- return {
123
- headers: {
124
- 'Content-Type': 'application/json',
125
- 'Cache-Control': 'public, max-age=86400',
126
- },
127
- data: content
128
- }
129
- }
130
- }
131
-
132
- const whereConditions = [
133
- registerQuery || '1=1',
134
- /*where ||*/ 'true',
135
- ].join(' AND ');
136
-
137
- const quotedTable = table.split('.').map(el => `"${el}"`).join('.');
138
-
139
- const countQuery = `
140
- SELECT COUNT(*) as total
141
- FROM ${quotedTable}
142
- WHERE ${whereConditions}
143
- `;
144
-
145
- const dataQuery = `
146
- SELECT "${pk}" as id ${props ? ', ' + props : ''}
147
- FROM ${quotedTable}
148
- WHERE ${whereConditions}
149
- ${orderBy ? `ORDER BY ${orderBy}` : ''}
150
- LIMIT ${limitNum}
151
- OFFSET ${offset}
152
- `;
153
-
154
- if (sql === 1) return { countQuery, dataQuery };
155
- if (sql === 2) return filepath.replace(/\\/g, '/');
156
-
157
-
158
- const [countResult, dataResult] = await Promise.all([
159
- pg.query(countQuery),
160
- pg.query(dataQuery),
161
- ]);
162
-
163
- const total = parseInt(countResult.rows[0]?.total || 0, 10);
164
- const rows = dataResult.rows || [];
165
-
166
- // Обробка класифікаторів
167
- if (columns && Array.isArray(columns)) {
168
- const classifiers = columns
169
- .filter(col => col.data && ['select', 'badge', 'tags', 'integer', 'text', 'text[]'].includes(col.format))
170
- .reduce((acc, curr) => ({ ...acc, [curr.name]: curr.data }), {});
171
-
172
- if (Object.keys(classifiers).length > 0) {
173
- await metaFormat({
174
- rows,
175
- table,
176
- cls: classifiers,
177
- suffix: true,
178
- });
179
- }
180
- }
181
-
182
- const result = {
183
- register_id: registerId,
184
- total,
185
- page: pageNum,
186
- limit: limitNum,
187
- pages: Math.ceil(total / limitNum),
188
- data: rows,
189
- };
190
-
191
- const jsonString = JSON.stringify(result);
192
-
193
- if (!nocache && !unittest) {
194
- await mkdir(path.dirname(filepath), { recursive: true });
195
- await writeFile(filepath, jsonString, 'utf8');
196
- }
197
-
198
- return {
199
- headers: {
200
- 'Content-Type': 'application/json',
201
- 'Cache-Control': nocache ? 'no-cache' : 'public, max-age=86400',
202
- },
203
- data: jsonString
204
- }
205
-
206
- }
1
+ import path from 'node:path';
2
+ import { existsSync } from 'node:fs';
3
+ import { createHash } from 'node:crypto';
4
+ import {
5
+ readFile, stat, mkdir, writeFile,
6
+ } from 'node:fs/promises';
7
+
8
+ import {
9
+ pgClients, getMeta, metaFormat,
10
+ } from '@opengis/fastify-table/utils.js';
11
+
12
+ import rootFolder from '../../../plugins/mapnik/funcs/rootFolder.mjs';
13
+ import { BadRequestError, NotFoundError } from '@opengis/fastify-table/errors.js';
14
+
15
+ const systemColumns = ['uid', 'cdate', 'editor_id', 'editor_date', 'created_by', 'created_at', 'updated_by', 'updated_at', 'geom'];
16
+
17
+ const unittest = process.env.NODE_ENV === 'test' || process.env.VITEST;
18
+
19
+ /**
20
+ * Повертає JSON дані для реєстру на основі налаштувань з gis.registers
21
+ *
22
+ * @method GET
23
+ * @param {string} params.layer - register_id
24
+ * @param {string} query.page - номер сторінки (default: 1)
25
+ * @param {string} query.limit - кількість записів на сторінку (default: 100)
26
+ * @param {string} query.where - додаткова WHERE умова
27
+ * @param {string} query.sql - повернути SQL запит замість даних
28
+ * @param {boolean} query.nocache - не використовувати кеш
29
+ */
30
+ export default async function jsonData({
31
+ layer,
32
+ page = 1,
33
+ limit = 100,
34
+ // where,
35
+ sql,
36
+ nocache
37
+ }, pg = pgClients.client) {
38
+ if (!layer) {
39
+ throw BadRequestError('not enough params: layer (register_id)');
40
+ }
41
+
42
+ const registerId = layer.replace('.json', '');
43
+ const pageNum = parseInt(page, 10) || 1;
44
+ const limitNum = Math.min(parseInt(limit, 10) || 100, 1000); // max 1000
45
+ const offset = (pageNum - 1) * limitNum;
46
+
47
+ if (!pg.pk?.['gis.registers']) {
48
+ throw NotFoundError('registers table not found');
49
+ }
50
+
51
+ const register = await pg.query(
52
+ `select
53
+ table_name,
54
+ pk,
55
+ query,
56
+ columns,
57
+ is_public,
58
+ is_active,
59
+ "order"
60
+ from gis.registers
61
+ where register_id = $1 and is_active = true and is_public = true`,
62
+ [registerId],
63
+ ).then(r => r.rows?.[0]);
64
+
65
+ if (!register) {
66
+ throw NotFoundError('register not found or not available');
67
+ }
68
+
69
+ const {
70
+ table_name: table,
71
+ pk,
72
+ query: registerQuery,
73
+ columns,
74
+ order: orderBy,
75
+ } = register;
76
+
77
+ if (!table) {
78
+ throw BadRequestError('invalid register table_name');
79
+ }
80
+
81
+ if (!pg.pk?.[table]?.length) {
82
+ throw NotFoundError('table not found');
83
+ }
84
+
85
+ const meta = await getMeta({ pg, table });
86
+ const { columns: metaColumns = [] } = meta || {};
87
+
88
+ let attributeColumns = [];
89
+ if (columns && Array.isArray(columns)) {
90
+ attributeColumns = columns
91
+ .filter(col => col.name && !systemColumns.includes(col.name))
92
+ .map(col => col.name);
93
+ }
94
+
95
+ const columnsFiltered = attributeColumns.length > 0
96
+ ? metaColumns.filter(col => attributeColumns.includes(col.name) && !systemColumns.includes(col.name))
97
+ : metaColumns.filter(col => !systemColumns.includes(col.name));
98
+
99
+ const props = columnsFiltered.map(el =>
100
+ `"${el.name}"${['int4'].includes(el.type) ? '::text' : ''}`
101
+ ).join(', ');
102
+
103
+ if (!props) {
104
+ throw BadRequestError('no columns to select');
105
+ }
106
+
107
+ const cacheHash = createHash('md5')
108
+ .update([registerId, /*where,*/ registerQuery, pageNum, limitNum].filter(el => el).join('-'))
109
+ .digest('hex');
110
+
111
+ const today = new Date().toISOString().split('T')[0];
112
+ const filepath = path.join(
113
+ rootFolder,
114
+ `/json/${registerId}/${today}/${cacheHash}.json`,
115
+ );
116
+
117
+ if (existsSync(filepath) && !nocache && !sql && !unittest) {
118
+ const { birthtimeMs = Date.now() } = await stat(filepath);
119
+ const ageInMs = Date.now() - birthtimeMs;
120
+ if (ageInMs < 86400000) {
121
+ const content = await readFile(filepath, 'utf8');
122
+ return {
123
+ headers: {
124
+ 'Content-Type': 'application/json',
125
+ 'Cache-Control': 'public, max-age=86400',
126
+ },
127
+ data: content
128
+ }
129
+ }
130
+ }
131
+
132
+ const whereConditions = [
133
+ registerQuery || '1=1',
134
+ /*where ||*/ 'true',
135
+ ].join(' AND ');
136
+
137
+ const quotedTable = table.split('.').map(el => `"${el}"`).join('.');
138
+
139
+ const countQuery = `
140
+ SELECT COUNT(*) as total
141
+ FROM ${quotedTable}
142
+ WHERE ${whereConditions}
143
+ `;
144
+
145
+ const dataQuery = `
146
+ SELECT "${pk}" as id ${props ? ', ' + props : ''}
147
+ FROM ${quotedTable}
148
+ WHERE ${whereConditions}
149
+ ${orderBy ? `ORDER BY ${orderBy}` : ''}
150
+ LIMIT ${limitNum}
151
+ OFFSET ${offset}
152
+ `;
153
+
154
+ if (sql === 1) return { countQuery, dataQuery };
155
+ if (sql === 2) return filepath.replace(/\\/g, '/');
156
+
157
+
158
+ const [countResult, dataResult] = await Promise.all([
159
+ pg.query(countQuery),
160
+ pg.query(dataQuery),
161
+ ]);
162
+
163
+ const total = parseInt(countResult.rows[0]?.total || 0, 10);
164
+ const rows = dataResult.rows || [];
165
+
166
+ // Обробка класифікаторів
167
+ if (columns && Array.isArray(columns)) {
168
+ const classifiers = columns
169
+ .filter(col => col.data && ['select', 'badge', 'tags', 'integer', 'text', 'text[]'].includes(col.format))
170
+ .reduce((acc, curr) => ({ ...acc, [curr.name]: curr.data }), {});
171
+
172
+ if (Object.keys(classifiers).length > 0) {
173
+ await metaFormat({
174
+ rows,
175
+ table,
176
+ cls: classifiers,
177
+ suffix: true,
178
+ });
179
+ }
180
+ }
181
+
182
+ const result = {
183
+ register_id: registerId,
184
+ total,
185
+ page: pageNum,
186
+ limit: limitNum,
187
+ pages: Math.ceil(total / limitNum),
188
+ data: rows,
189
+ };
190
+
191
+ const jsonString = JSON.stringify(result);
192
+
193
+ if (!nocache && !unittest) {
194
+ await mkdir(path.dirname(filepath), { recursive: true });
195
+ await writeFile(filepath, jsonString, 'utf8');
196
+ }
197
+
198
+ return {
199
+ headers: {
200
+ 'Content-Type': 'application/json',
201
+ 'Cache-Control': nocache ? 'no-cache' : 'public, max-age=86400',
202
+ },
203
+ data: jsonString
204
+ }
205
+
206
+ }
@@ -1,102 +1,102 @@
1
- import {
2
- pgClients, yml2json, getTemplates, getTemplate,
3
- } from '@opengis/fastify-table/utils.js';
4
-
5
- import getPermissions from '../../permissions/functions/get.permissions.js';
6
-
7
- export default async function layerList({
8
- sql, uid,
9
- }, pg = pgClients.client) {
10
-
11
- const layers = getTemplates('layer');
12
- const files = Promise.all(layers.map(async (el) => {
13
- const layer = await getTemplate('layer', el[0]);
14
- return layer;
15
- }));
16
-
17
- if (!pg.pk?.['gis.services'] && !pg.pk?.['gis.ogc_service'] && !pg.pk?.['gis.rasters'] && !pg.pk?.['gis.cartocss']) {
18
- return files;
19
- }
20
-
21
- const { all_layers, layer_list } = uid ? await getPermissions({ pg, uid }) : { all_layers: false, layer_list: [] };
22
-
23
- const whereServices = (all_layers === true) ? '1=1'
24
- : (uid && !all_layers) ? '( s.is_public or s.service_id = any($1))'
25
- : 'is_public';
26
-
27
- const whereOgcServices = (all_layers === true) ? '1=1'
28
- : (uid && !all_layers) ? '( s.ispublic or s.ogc_service_id = any($1))'
29
- : 'ispublic';
30
-
31
- const whereRasters = (all_layers === true) ? '1=1'
32
- : (uid && !all_layers) ? '(s.is_public or s.raster_id = any($1))'
33
- : 'is_public';
34
-
35
- const whereCartocss = (all_layers === true) ? '1=1'
36
- : (uid && !all_layers) ? '(s.is_public or s.cartocss_id = any($1))'
37
- : 'is_public';
38
- const q = `
39
- select * from
40
- (
41
- 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,
42
- popup, card, filters, source_path, legend
43
- from gis.services s where is_active and
44
- ${whereServices}
45
- union all
46
- 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,
47
- null as popup, null as card, null as filters, table_name as source_path, null as legend
48
- from gis.ogc_service s where enabled and
49
- ${whereOgcServices}
50
- union all
51
- select raster_id as id, name, null as category, null as style, geom::box2d as extent, st_asgeojson(geom)::json as geom,
52
- coalesce('/api/gis-rtile/'||rtrim(
53
- replace(
54
- replace(
55
- encode(source_path::bytea, 'base64'),
56
- '+', '-'
57
- ),
58
- '/', '_'
59
- ),
60
- '='
61
- )||'/{z}/{x}/{y}.png',null) as url, 'raster' as service, group_id,
62
- null as popup, null as card, null as filters, source_path, null as legend
63
- from gis.rasters s where is_active and
64
- ${whereRasters}
65
- union all
66
- select cartocss_id as id, name, null as category, style, geom::box2d as bbox, st_asgeojson(geom)::json as geom,
67
- coalesce('/api/gis-rtile/'||cartocss_id||'/{z}/{x}/{y}.png',null) as url, 'cartocss' as service, group_id,
68
- null as popup, null as card, null as filters, null as source_path, null as legend
69
- from gis.cartocss s where enabled and
70
- ${whereCartocss}
71
- )q order by q.name
72
- `;
73
-
74
- if (uid && sql) return q;
75
-
76
- const rows = await pg.query(q, (uid && !all_layers) ? [layer_list] : []).then(r => r.rows || []);
77
-
78
- const totals = pg.queryCache ? await pg.queryCache('select json_object_agg(oid::regclass, reltuples) from pg_class')
79
- .then(r => r.rows?.[0]?.json_object_agg || {}) : {};
80
- rows.filter(row => row.source_path).forEach(row => Object.assign(row, { count: totals[row.source_path] || 0 }));
81
-
82
- const groupIds = rows.map(el => el.group_id).filter(Boolean);
83
- const groupNames = groupIds.length ? await pg.query('select json_object_agg(group_id,group_name) from gis.group_list where group_id=any($1)', [groupIds]).then(r => r.rows?.[0]?.json_object_agg || {}) : {};
84
- rows.filter(el => el.group_id).forEach(row => Object.assign(row, { group_name: groupNames[row.group_id] }));
85
-
86
- if (!rows.length) {
87
- return [];
88
- }
89
-
90
- // parse service style
91
- rows.forEach(row => Object.assign(row, { style: row.style && ['vtile', 'geojson'].includes(row.service) ? yml2json(row.style) : row.style }));
92
- // parse extent string to number[]
93
- rows.filter(row => row.extent).forEach(row => Object.assign(row, {
94
- extent: row.extent.match(/BOX\(([^)]+)\)/)?.[1]
95
- ?.replace?.(/ /g, ',')
96
- ?.split?.(','),
97
- }));
98
-
99
- // return files;
100
-
101
- return rows.concat(files);
102
- }
1
+ import {
2
+ pgClients, yml2json, getTemplates, getTemplate,
3
+ } from '@opengis/fastify-table/utils.js';
4
+
5
+ import getPermissions from '../../permissions/functions/get.permissions.js';
6
+
7
+ export default async function layerList({
8
+ sql, uid,
9
+ }, pg = pgClients.client) {
10
+
11
+ const layers = getTemplates('layer');
12
+ const files = Promise.all(layers.map(async (el) => {
13
+ const layer = await getTemplate('layer', el[0]);
14
+ return layer;
15
+ }));
16
+
17
+ if (!pg.pk?.['gis.services'] && !pg.pk?.['gis.ogc_service'] && !pg.pk?.['gis.rasters'] && !pg.pk?.['gis.cartocss']) {
18
+ return files;
19
+ }
20
+
21
+ const { all_layers, layer_list } = uid ? await getPermissions({ pg, uid }) : { all_layers: false, layer_list: [] };
22
+
23
+ const whereServices = (all_layers === true) ? '1=1'
24
+ : (uid && !all_layers) ? '( s.is_public or s.service_id = any($1))'
25
+ : 'is_public';
26
+
27
+ const whereOgcServices = (all_layers === true) ? '1=1'
28
+ : (uid && !all_layers) ? '( s.ispublic or s.ogc_service_id = any($1))'
29
+ : 'ispublic';
30
+
31
+ const whereRasters = (all_layers === true) ? '1=1'
32
+ : (uid && !all_layers) ? '(s.is_public or s.raster_id = any($1))'
33
+ : 'is_public';
34
+
35
+ const whereCartocss = (all_layers === true) ? '1=1'
36
+ : (uid && !all_layers) ? '(s.is_public or s.cartocss_id = any($1))'
37
+ : 'is_public';
38
+ const q = `
39
+ select * from
40
+ (
41
+ 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,
42
+ popup, card, filters, source_path, legend
43
+ from gis.services s where is_active and
44
+ ${whereServices}
45
+ union all
46
+ 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,
47
+ null as popup, null as card, null as filters, table_name as source_path, null as legend
48
+ from gis.ogc_service s where enabled and
49
+ ${whereOgcServices}
50
+ union all
51
+ select raster_id as id, name, null as category, null as style, geom::box2d as extent, st_asgeojson(geom)::json as geom,
52
+ coalesce('/api/gis-rtile/'||rtrim(
53
+ replace(
54
+ replace(
55
+ encode(source_path::bytea, 'base64'),
56
+ '+', '-'
57
+ ),
58
+ '/', '_'
59
+ ),
60
+ '='
61
+ )||'/{z}/{x}/{y}.png',null) as url, 'raster' as service, group_id,
62
+ null as popup, null as card, null as filters, source_path, null as legend
63
+ from gis.rasters s where is_active and
64
+ ${whereRasters}
65
+ union all
66
+ select cartocss_id as id, name, null as category, style, geom::box2d as bbox, st_asgeojson(geom)::json as geom,
67
+ coalesce('/api/gis-rtile/'||cartocss_id||'/{z}/{x}/{y}.png',null) as url, 'cartocss' as service, group_id,
68
+ null as popup, null as card, null as filters, null as source_path, null as legend
69
+ from gis.cartocss s where enabled and
70
+ ${whereCartocss}
71
+ )q order by q.name
72
+ `;
73
+
74
+ if (uid && sql) return q;
75
+
76
+ const rows = await pg.query(q, (uid && !all_layers) ? [layer_list] : []).then(r => r.rows || []);
77
+
78
+ const totals = pg.queryCache ? await pg.queryCache('select json_object_agg(oid::regclass, reltuples) from pg_class')
79
+ .then(r => r.rows?.[0]?.json_object_agg || {}) : {};
80
+ rows.filter(row => row.source_path).forEach(row => Object.assign(row, { count: totals[row.source_path] || 0 }));
81
+
82
+ const groupIds = rows.map(el => el.group_id).filter(Boolean);
83
+ const groupNames = groupIds.length ? await pg.query('select json_object_agg(group_id,group_name) from gis.group_list where group_id=any($1)', [groupIds]).then(r => r.rows?.[0]?.json_object_agg || {}) : {};
84
+ rows.filter(el => el.group_id).forEach(row => Object.assign(row, { group_name: groupNames[row.group_id] }));
85
+
86
+ if (!rows.length) {
87
+ return [];
88
+ }
89
+
90
+ // parse service style
91
+ rows.forEach(row => Object.assign(row, { style: row.style && ['vtile', 'geojson'].includes(row.service) ? yml2json(row.style) : row.style }));
92
+ // parse extent string to number[]
93
+ rows.filter(row => row.extent).forEach(row => Object.assign(row, {
94
+ extent: row.extent.match(/BOX\(([^)]+)\)/)?.[1]
95
+ ?.replace?.(/ /g, ',')
96
+ ?.split?.(','),
97
+ }));
98
+
99
+ // return files;
100
+
101
+ return rows.concat(files);
102
+ }