@opengis/gis 0.2.208 → 0.2.209

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 (221) hide show
  1. package/README.md +181 -181
  2. package/dist/{CardIcon-iGo8QJu9.js → CardIcon-B6rIgAoD.js} +1 -1
  3. package/dist/{EntityTablePage-BiVoVAhN.js → EntityTablePage-CfLq5znM.js} +2 -2
  4. package/dist/{ExtentOutlineLayer.vue_vue_type_script_setup_true_lang-BdL5cQgN.js → ExtentOutlineLayer.vue_vue_type_script_setup_true_lang-CB_4eJz9.js} +1 -1
  5. package/dist/{MapSettings-CXqiYxV4.js → MapSettings-fwcVWgdK.js} +2 -2
  6. package/dist/{MapToolbarRight.vue_vue_type_script_setup_true_lang-BHCChxmg.js → MapToolbarRight.vue_vue_type_script_setup_true_lang-BWqBARGq.js} +1 -1
  7. package/dist/{RastersTablePage-Dgk1wp3d.js → RastersTablePage-XHV40tf_.js} +2 -2
  8. package/dist/{cartocss-BIpgQU6F.js → cartocss-BjGlng_r.js} +526 -503
  9. package/dist/{import-utils-CfXKgZFd.js → import-utils-WfWvX9B5.js} +1 -1
  10. package/dist/{index-CM_DTEUa.js → index-CDy0MSfg.js} +3509 -3461
  11. package/dist/index.css +1 -1
  12. package/dist/index.js +1 -1
  13. package/dist/index.umd.cjs +42 -48
  14. package/dist/{raster-D_vEBha8.js → raster-D2X_jR9m.js} +3 -3
  15. package/dist/{register-C5_Un1Ms.js → register-Ctn9pgUE.js} +3 -3
  16. package/dist/service-CiUwLEwY.js +3484 -0
  17. package/dist/{vs-datatable--K-DxayK.js → vs-datatable-BixMLOv-.js} +4 -3
  18. package/module/gis/card/gis.metadata.table/index.yml +22 -22
  19. package/module/gis/card/gis.rasters.table/index.yml +11 -11
  20. package/module/gis/card/gis.registers.table/index.yml +23 -23
  21. package/module/gis/card/gis.services.table/index.yml +25 -25
  22. package/module/gis/cls/bool.yes_no.json +12 -12
  23. package/module/gis/cls/encoding.json +14 -14
  24. package/module/gis/cls/geom_type.json +14 -14
  25. package/module/gis/cls/gis.column_type.json +34 -34
  26. package/module/gis/cls/gis.column_view_type.json +26 -26
  27. package/module/gis/cls/gis.filter_type.json +22 -22
  28. package/module/gis/cls/language.json +10 -10
  29. package/module/gis/cls/meta.service_type.json +42 -42
  30. package/module/gis/cls/ogc.service.json +21 -21
  31. package/module/gis/cls/service_type.json +42 -42
  32. package/module/gis/cls/source_type.json +10 -10
  33. package/module/gis/cls/standarts.json +6 -6
  34. package/module/gis/cls/topic_category.json +106 -106
  35. package/module/gis/cls/update_frequency.json +29 -29
  36. package/module/gis/cls/view.json +21 -21
  37. package/module/gis/form/feedback.answer.form.json +10 -10
  38. package/module/gis/form/gis.cartocss.form.json +64 -64
  39. package/module/gis/form/gis.group_list.form.json +17 -17
  40. package/module/gis/form/gis.maps.form.json +61 -61
  41. package/module/gis/form/gis.metadata.form.json +240 -240
  42. package/module/gis/form/gis.metadata_new.form.json +195 -195
  43. package/module/gis/form/gis.ogc_service.form.json +51 -51
  44. package/module/gis/form/gis.rasters.form.json +76 -76
  45. package/module/gis/form/gis.registers.form.json +127 -127
  46. package/module/gis/form/gis.registers_column.form.json +84 -84
  47. package/module/gis/form/gis.registers_filter.form.json +65 -65
  48. package/module/gis/form/gis.services.form.json +111 -111
  49. package/module/gis/form/gis.services_attributes.form.json +75 -75
  50. package/module/gis/form/gis.services_filter.form.json +65 -65
  51. package/module/gis/menu.json +43 -43
  52. package/module/gis/select/admin.cls.name.sql +9 -9
  53. package/module/gis/select/layer_list.sql +7 -7
  54. package/module/gis/select/layer_list_text.sql +7 -7
  55. package/module/gis/select/pg.column_name.geometry.sql +12 -12
  56. package/module/gis/select/pg.columns.parent.sql +6 -6
  57. package/module/gis/select/pg.table_name.sql +17 -17
  58. package/module/gis/select/service_id.sql +1 -1
  59. package/module/gis/select/srid.sql +7 -7
  60. package/module/gis/table/gis.cartocss.table.json +74 -74
  61. package/module/gis/table/gis.group_list.table.json +58 -58
  62. package/module/gis/table/gis.maps.table.json +110 -110
  63. package/module/gis/table/gis.metadata.table.json +70 -70
  64. package/module/gis/table/gis.metadata_new.table.json +137 -137
  65. package/module/gis/table/gis.ogc_service.table.json +100 -100
  66. package/module/gis/table/gis.rasters.table.json +113 -113
  67. package/module/gis/table/gis.registers.table.json +143 -143
  68. package/module/gis/table/gis.services.table.json +120 -120
  69. package/module/gis/table/site.gis.registers.table.json +88 -88
  70. package/module/gis/table/site.gis.services.table.json +106 -106
  71. package/module/gis/templates/ISO19136_2017_gml_template.xml +330 -330
  72. package/module/gis/tokens.yml +5 -5
  73. package/module/permissions/form/permissions.users.form.json +151 -151
  74. package/module/permissions/table/gis.permissions.table.json +97 -97
  75. package/module/test/map/addr.json +302 -302
  76. package/module/test/map/addr1.yml +23 -23
  77. package/module/test/select/address.str_id.sql +3 -3
  78. package/package.json +79 -79
  79. package/plugin.js +64 -64
  80. package/server/migrations/array_intersect.sql +13 -13
  81. package/server/migrations/cartocss.sql +27 -27
  82. package/server/migrations/group_list.sql +74 -74
  83. package/server/migrations/maps.sql +30 -30
  84. package/server/migrations/metadata.sql +415 -415
  85. package/server/migrations/ogc.sql +106 -106
  86. package/server/migrations/rasters.sql +265 -265
  87. package/server/migrations/services.sql +248 -248
  88. package/server/migrations/services_users_rel.sql +22 -22
  89. package/server/migrations/widgets.sql +20 -20
  90. package/server/plugins/crons.js +21 -21
  91. package/server/plugins/mapnik/funcs/checkRasterFile.js +107 -107
  92. package/server/plugins/mapnik/funcs/mapnik.js +151 -151
  93. package/server/plugins/mapnik/funcs/rootFolder.mjs +8 -8
  94. package/server/plugins/mapnik/map.proto +437 -437
  95. package/server/plugins/vite.js +74 -74
  96. package/server/routes/cartocss/cartocss.route.js +31 -31
  97. package/server/routes/cartocss/cartocss.route.test.js +78 -78
  98. package/server/routes/cartocss/cartocss.schema.js +76 -76
  99. package/server/routes/cartocss/functions/add.cartocss.js +39 -39
  100. package/server/routes/cartocss/functions/get.cartocss.js +57 -57
  101. package/server/routes/gis/functions/checkXML.js +107 -107
  102. package/server/routes/gis/functions/dashboard.js +24 -24
  103. package/server/routes/gis/gis.route.js +26 -26
  104. package/server/routes/gis/gis.route.test.js +33 -33
  105. package/server/routes/map/fonts/index.js +1933 -1933
  106. package/server/routes/map/functions/clearTiles.js +35 -35
  107. package/server/routes/map/functions/geojson.js +187 -187
  108. package/server/routes/map/functions/gis.convert.js +65 -65
  109. package/server/routes/map/functions/gis.icon.js +327 -327
  110. package/server/routes/map/functions/jsonData.js +206 -206
  111. package/server/routes/map/functions/layerList.js +144 -144
  112. package/server/routes/map/functions/map.js +122 -122
  113. package/server/routes/map/functions/mapCatalog.js +72 -72
  114. package/server/routes/map/functions/mapCatalogAttribute.js +53 -53
  115. package/server/routes/map/functions/mapFeatures.js +133 -133
  116. package/server/routes/map/functions/mapFormat.js +246 -246
  117. package/server/routes/map/functions/mapTiles.js +162 -162
  118. package/server/routes/map/functions/maps.js +15 -15
  119. package/server/routes/map/functions/marker_icon.js +43 -43
  120. package/server/routes/map/functions/parseGeoFile.js +85 -85
  121. package/server/routes/map/functions/pointHeight.js +51 -51
  122. package/server/routes/map/functions/vtile.js +174 -174
  123. package/server/routes/map/functions/vtile1.js +191 -191
  124. package/server/routes/map/map.route.js +283 -283
  125. package/server/routes/map/map.route.test.js +693 -693
  126. package/server/routes/map/map.schema.js +356 -356
  127. package/server/routes/map/pin/circle1.svg +76 -76
  128. package/server/routes/map/pin/circle2.svg +18 -18
  129. package/server/routes/map/pin/none.svg +12 -12
  130. package/server/routes/map/pin/pin.svg +14 -14
  131. package/server/routes/map/pin/pin1.svg +16 -16
  132. package/server/routes/map/pin/pin2.svg +7 -7
  133. package/server/routes/map/pin/pin3.svg +34 -34
  134. package/server/routes/map/pin/pin4.svg +14 -14
  135. package/server/routes/map/pin/pin5.svg +7 -7
  136. package/server/routes/map/pin/pin6.svg +12 -12
  137. package/server/routes/map/pin/pin7.svg +12 -12
  138. package/server/routes/mapnik/functions/cartoBounds.js +32 -32
  139. package/server/routes/mapnik/functions/clearTiles.js +103 -103
  140. package/server/routes/mapnik/functions/convertBoundToTile.js +27 -27
  141. package/server/routes/mapnik/functions/createXml.js +76 -76
  142. package/server/routes/mapnik/functions/createXmlMulti.js +72 -72
  143. package/server/routes/mapnik/functions/fileSearch.js +35 -35
  144. package/server/routes/mapnik/functions/fileStat.js +28 -28
  145. package/server/routes/mapnik/functions/pretile.js +138 -138
  146. package/server/routes/mapnik/functions/rasterInfo.js +66 -66
  147. package/server/routes/mapnik/functions/readDir.js +22 -22
  148. package/server/routes/mapnik/functions/rtile.js +164 -164
  149. package/server/routes/mapnik/functions/uploadRaster.js +152 -152
  150. package/server/routes/mapnik/functions/uploadXML.js +140 -140
  151. package/server/routes/mapnik/mapnik.route.js +102 -102
  152. package/server/routes/mapnik/mapnik.route.test.js +370 -370
  153. package/server/routes/mapnik/mapnik.schema.mjs +195 -195
  154. package/server/routes/mapnik.prefixless/functions/mapnikLogger.js +31 -31
  155. package/server/routes/mapnik.prefixless/functions/mapnikStat.js +21 -21
  156. package/server/routes/mapnik.prefixless/mapnik.prefixless.route.js +20 -20
  157. package/server/routes/mapnik.prefixless/mapnik.prefixless.route.test.js +91 -91
  158. package/server/routes/mapnik.prefixless/mapnik.prefixless.schema.mjs +27 -27
  159. package/server/routes/maps/functions/add.map.js +42 -42
  160. package/server/routes/maps/functions/del.map.js +17 -17
  161. package/server/routes/maps/functions/get.map.js +119 -119
  162. package/server/routes/maps/maps.route.js +58 -58
  163. package/server/routes/maps/maps.route.test.js +231 -231
  164. package/server/routes/maps/maps.schema.js +9 -9
  165. package/server/routes/metadata/functions/editMetadata.js +35 -35
  166. package/server/routes/metadata/functions/metadataXML.js +19 -19
  167. package/server/routes/metadata/metadata.route.js +26 -26
  168. package/server/routes/metadata/metadata.route.test.js +46 -46
  169. package/server/routes/metadata/metadata.schema.js +53 -53
  170. package/server/routes/ogc/functions/map.info.point.js +117 -117
  171. package/server/routes/ogc/ogc.route.js +21 -21
  172. package/server/routes/ogc/ogc.route.test.js +53 -53
  173. package/server/routes/ogc/ogc.schema.js +16 -16
  174. package/server/routes/permissions/functions/catalog.permissions.edit.js +20 -20
  175. package/server/routes/permissions/functions/catalog.permissions.js +12 -12
  176. package/server/routes/permissions/functions/get.permissions.js +59 -59
  177. package/server/routes/permissions/functions/gis.catalog.js +80 -80
  178. package/server/routes/permissions/permissions.route.js +35 -35
  179. package/server/routes/permissions/permissions.route.test.js +35 -35
  180. package/server/routes/permissions/permissions.schema.js +43 -43
  181. package/server/routes/registers/functions/add.registry.js +37 -37
  182. package/server/routes/registers/functions/classifiers.js +100 -100
  183. package/server/routes/registers/functions/columns.js +3 -3
  184. package/server/routes/registers/functions/content.type.js +9 -9
  185. package/server/routes/registers/functions/del.registry.js +14 -14
  186. package/server/routes/registers/functions/get.info.js +93 -93
  187. package/server/routes/registers/functions/getFilterSQLParametrized/formatValue.js +328 -328
  188. package/server/routes/registers/functions/getFilterSQLParametrized/getFilterQuery.js +126 -126
  189. package/server/routes/registers/functions/getFilterSQLParametrized/getRangeQuery.js +353 -353
  190. package/server/routes/registers/functions/getFilterSQLParametrized/index.js +81 -81
  191. package/server/routes/registers/functions/getTableColumnMeta.js +148 -148
  192. package/server/routes/registers/functions/gis.export.js +159 -159
  193. package/server/routes/registers/functions/gis.registry.js +71 -71
  194. package/server/routes/registers/functions/gis.registry.list.js +61 -61
  195. package/server/routes/registers/functions/gis.suggest.js +310 -310
  196. package/server/routes/registers/functions/handleRegistryRequest.js +178 -178
  197. package/server/routes/registers/functions/map.registry.js +87 -87
  198. package/server/routes/registers/registers.route.js +92 -92
  199. package/server/routes/registers/registers.route.test.js +173 -173
  200. package/server/routes/registers/registers.schema.js +276 -276
  201. package/server/routes/root.mjs +3 -3
  202. package/server/routes/services/functions/add.service.js +62 -62
  203. package/server/routes/services/functions/create.route.js +93 -93
  204. package/server/routes/services/functions/del.service.js +12 -12
  205. package/server/routes/services/functions/get.layer.geom.js +27 -27
  206. package/server/routes/services/functions/get.service.users.js +76 -76
  207. package/server/routes/services/functions/get.services.col.js +34 -34
  208. package/server/routes/services/functions/get.services.js +124 -124
  209. package/server/routes/services/functions/legend.auto.js +77 -77
  210. package/server/routes/services/services.route.js +76 -76
  211. package/server/routes/services/services.route.test.js +171 -171
  212. package/server/routes/services/services.schema.js +459 -459
  213. package/server/routes/widgets/functions/add.widget.js +38 -38
  214. package/server/routes/widgets/functions/del.widget.js +17 -17
  215. package/server/routes/widgets/functions/get.widget.js +41 -41
  216. package/server/routes/widgets/widgets.route.js +61 -61
  217. package/server/routes/widgets/widgets.route.test.js +144 -144
  218. package/server/routes/widgets/widgets.schema.js +24 -24
  219. package/server/shared/listFiles.js +14 -14
  220. package/utils.js +13 -13
  221. package/dist/service-JN82JN81.js +0 -3676
@@ -1,35 +1,35 @@
1
- import { BadRequestError, NotFoundError } from "@opengis/fastify-table/errors.js";
2
- import { pgClients, dataUpsert } from "@opengis/fastify-table/utils.js";
3
-
4
- export default async function editMetadata({ id, type, body, uid }, pg = pgClients.client) {
5
- if (!type) {
6
- throw BadRequestError('not enough params: type');
7
- }
8
-
9
- const q = {
10
- raster: 'select 1 from gis.rasters where raster_id = $1',
11
- css: 'select 1 from gis.cartocss where cartocss_id = $1',
12
- dataset: 'select 1 from gis.dataset where dataset_id = $1',
13
- service: 'select 1 from gis.services where service_id = $1',
14
- }[type];
15
-
16
- if (!q) {
17
- throw BadRequestError('invalid params: type');
18
- }
19
-
20
- const exists = await pg.query(q, [id]).then(r => r.rowCount || 0);
21
-
22
- if (!exists) {
23
- throw NotFoundError(`${type} not found: ${id}`);
24
- }
25
-
26
- const data = await dataUpsert({
27
- pg,
28
- id: id,
29
- table: 'gis.metadata',
30
- data: { ...body, type: type, layer_id: id },
31
- uid,
32
- });
33
-
34
- return data;
35
- }
1
+ import { BadRequestError, NotFoundError } from "@opengis/fastify-table/errors.js";
2
+ import { pgClients, dataUpsert } from "@opengis/fastify-table/utils.js";
3
+
4
+ export default async function editMetadata({ id, type, body, uid }, pg = pgClients.client) {
5
+ if (!type) {
6
+ throw BadRequestError('not enough params: type');
7
+ }
8
+
9
+ const q = {
10
+ raster: 'select 1 from gis.rasters where raster_id = $1',
11
+ css: 'select 1 from gis.cartocss where cartocss_id = $1',
12
+ dataset: 'select 1 from gis.dataset where dataset_id = $1',
13
+ service: 'select 1 from gis.services where service_id = $1',
14
+ }[type];
15
+
16
+ if (!q) {
17
+ throw BadRequestError('invalid params: type');
18
+ }
19
+
20
+ const exists = await pg.query(q, [id]).then(r => r.rowCount || 0);
21
+
22
+ if (!exists) {
23
+ throw NotFoundError(`${type} not found: ${id}`);
24
+ }
25
+
26
+ const data = await dataUpsert({
27
+ pg,
28
+ id: id,
29
+ table: 'gis.metadata',
30
+ data: { ...body, type: type, layer_id: id },
31
+ uid,
32
+ });
33
+
34
+ return data;
35
+ }
@@ -1,19 +1,19 @@
1
- import { handlebars, getTemplate } from "@opengis/fastify-table/utils.js";
2
- import { BadRequestError } from "@opengis/fastify-table/errors.js";
3
-
4
- // currently unused
5
- export default async function metadataXml({ id }) {
6
- if (!id) {
7
- throw BadRequestError('not enough params: id');
8
- }
9
-
10
- const pt = await getTemplate('templates', 'ISO19136_2017_gml_template');
11
- const data = await handlebars.compile(pt)({ id });
12
-
13
- return {
14
- headers: {
15
- 'Content-Type': 'text/xml; charset=utf-8',
16
- },
17
- data
18
- };
19
- }
1
+ import { handlebars, getTemplate } from "@opengis/fastify-table/utils.js";
2
+ import { BadRequestError } from "@opengis/fastify-table/errors.js";
3
+
4
+ // currently unused
5
+ export default async function metadataXml({ id }) {
6
+ if (!id) {
7
+ throw BadRequestError('not enough params: id');
8
+ }
9
+
10
+ const pt = await getTemplate('templates', 'ISO19136_2017_gml_template');
11
+ const data = await handlebars.compile(pt)({ id });
12
+
13
+ return {
14
+ headers: {
15
+ 'Content-Type': 'text/xml; charset=utf-8',
16
+ },
17
+ data
18
+ };
19
+ }
@@ -1,26 +1,26 @@
1
- // import metadataXML from './functions/metadataXML.js';
2
- import editMetadata from './functions/editMetadata.js';
3
-
4
- import {
5
- editMetadataSchema,
6
- } from './metadata.schema.js';
7
-
8
- const privateParams = { config: { policy: 'L1', package: 'gis' } };
9
- // const publicParams = { config: { policy: 'L0', package: 'gis' } };
10
-
11
- async function route(app) {
12
- /*app.get('/xml/:id', { ...publicParams, schema: metadataXMLSchema }, async ({ params }, reply) => {
13
- const result = await metadataXML({ id: params.id });
14
- return reply.headers(result.headers).send(result.data);
15
- });*/
16
- app.post('/gis-metadata/:type/:id', { ...privateParams, schema: editMetadataSchema }, async ({ params, body, user, pg }) => {
17
- const result = await editMetadata({
18
- id: params.id,
19
- type: params.type,
20
- body,
21
- uid: user?.uid,
22
- }, pg);
23
- return result;
24
- });
25
- }
26
- export default route;
1
+ // import metadataXML from './functions/metadataXML.js';
2
+ import editMetadata from './functions/editMetadata.js';
3
+
4
+ import {
5
+ editMetadataSchema,
6
+ } from './metadata.schema.js';
7
+
8
+ const privateParams = { config: { policy: 'L1', package: 'gis' } };
9
+ // const publicParams = { config: { policy: 'L0', package: 'gis' } };
10
+
11
+ async function route(app) {
12
+ /*app.get('/xml/:id', { ...publicParams, schema: metadataXMLSchema }, async ({ params }, reply) => {
13
+ const result = await metadataXML({ id: params.id });
14
+ return reply.headers(result.headers).send(result.data);
15
+ });*/
16
+ app.post('/gis-metadata/:type/:id', { ...privateParams, schema: editMetadataSchema }, async ({ params, body, user, pg }) => {
17
+ const result = await editMetadata({
18
+ id: params.id,
19
+ type: params.type,
20
+ body,
21
+ uid: user?.uid,
22
+ }, pg);
23
+ return result;
24
+ });
25
+ }
26
+ export default route;
@@ -1,47 +1,47 @@
1
- import { afterAll, beforeAll, describe, expect, test } from 'vitest';
2
-
3
- import { getPGAsync } from '@opengis/fastify-table/utils.js';
4
-
5
- import { build, injectWithHeaders } from '../../../test/helper.js';
6
-
7
- let pg;
8
-
9
- beforeAll(async () => {
10
- await build();
11
-
12
- pg = await getPGAsync();
13
-
14
- await cleanUp('before');
15
- });
16
-
17
- afterAll(async () => {
18
- await cleanUp('after');
19
- });
20
-
21
- const testId = 'testCss';
22
- const user = { id: '2', type: 'admin' };
23
-
24
- const cleanUp = async (when) => {
25
- if (!pg) return;
26
- const rowCount = await pg.query('delete from gis.cartocss where cartocss_id=$1', [testId]).then(r => r.rowCount || 0);
27
- const rowCount3 = await pg.query('delete from gis.metadata where metadata_id=$1', [testId]).then(r => r.rowCount || 0);
28
- console.log(`clean up finished: ${when}`, rowCount, rowCount3);
29
- };
30
-
31
- describe('GIS routes', () => {
32
- test('POST /gis-metadata/:type/:id returns 200', async () => {
33
- await pg.query('insert into gis.cartocss(cartocss_id,name) values($1,$2)', [testId, 'unit-test']).catch(err => console.error(err));
34
- const res = await injectWithHeaders({
35
- method: 'POST',
36
- url: `/api/gis-metadata/css/${testId}`,
37
- payload: {
38
- layer_id: testId
39
- },
40
- headers: { uid: user.id, user_type: user.type }
41
- });
42
-
43
- expect(res.statusCode).toBe(200);
44
- expect(res.body).toHaveProperty('metadata_id');
45
- expect(res.body.metadata_id).toBe(testId);
46
- });
1
+ import { afterAll, beforeAll, describe, expect, test } from 'vitest';
2
+
3
+ import { getPGAsync } from '@opengis/fastify-table/utils.js';
4
+
5
+ import { build, injectWithHeaders } from '../../../test/helper.js';
6
+
7
+ let pg;
8
+
9
+ beforeAll(async () => {
10
+ await build();
11
+
12
+ pg = await getPGAsync();
13
+
14
+ await cleanUp('before');
15
+ });
16
+
17
+ afterAll(async () => {
18
+ await cleanUp('after');
19
+ });
20
+
21
+ const testId = 'testCss';
22
+ const user = { id: '2', type: 'admin' };
23
+
24
+ const cleanUp = async (when) => {
25
+ if (!pg) return;
26
+ const rowCount = await pg.query('delete from gis.cartocss where cartocss_id=$1', [testId]).then(r => r.rowCount || 0);
27
+ const rowCount3 = await pg.query('delete from gis.metadata where metadata_id=$1', [testId]).then(r => r.rowCount || 0);
28
+ console.log(`clean up finished: ${when}`, rowCount, rowCount3);
29
+ };
30
+
31
+ describe('GIS routes', () => {
32
+ test('POST /gis-metadata/:type/:id returns 200', async () => {
33
+ await pg.query('insert into gis.cartocss(cartocss_id,name) values($1,$2)', [testId, 'unit-test']).catch(err => console.error(err));
34
+ const res = await injectWithHeaders({
35
+ method: 'POST',
36
+ url: `/api/gis-metadata/css/${testId}`,
37
+ payload: {
38
+ layer_id: testId
39
+ },
40
+ headers: { uid: user.id, user_type: user.type }
41
+ });
42
+
43
+ expect(res.statusCode).toBe(200);
44
+ expect(res.body).toHaveProperty('metadata_id');
45
+ expect(res.body.metadata_id).toBe(testId);
46
+ });
47
47
  });
@@ -1,53 +1,53 @@
1
- export const editMetadataSchema = {
2
- params: {
3
- type: 'object',
4
- required: ['type', 'id'],
5
- properties: {
6
- type: { type: 'string', enum: ['raster', 'css', 'dataset', 'service'] },
7
- id: { type: 'string', pattern: '^([\\d\\w._-]+)$' },
8
- },
9
- },
10
- body: {
11
- type: 'object',
12
- // additionalProperties: false,
13
- properties: {
14
- geom: {
15
- type: 'object',
16
- properties: {
17
- type: { type: 'string', enum: ['Point', 'LineString', 'Polygon'] },
18
- coordinates: { type: 'array' },
19
- },
20
- required: ['type', 'coordinates'],
21
- },
22
- description: { type: 'string' },
23
- group_id: { type: 'string' },
24
- keywords: {
25
- type: 'array',
26
- items: { type: 'string' },
27
- },
28
- is_public: { type: 'boolean' },
29
- is_active: { type: 'boolean' },
30
- service_key: { type: 'string' },
31
- producer: { type: 'string' },
32
- category: { type: 'string' },
33
- license: { type: 'string' },
34
- year: { type: 'string' },
35
- service_url: { type: 'string' },
36
- metadata_url: { type: 'string' },
37
- thumbnail_url: { type: 'string' },
38
- query: { type: 'string' },
39
- },
40
- },
41
- };
42
-
43
- export const metadataXMLSchema = {
44
- params: {
45
- type: 'object',
46
- required: ['id'],
47
- properties: {
48
- id: { type: 'string', pattern: '^([\\d\\w._-]+)$' },
49
- },
50
- },
51
- };
52
-
53
- export default null;
1
+ export const editMetadataSchema = {
2
+ params: {
3
+ type: 'object',
4
+ required: ['type', 'id'],
5
+ properties: {
6
+ type: { type: 'string', enum: ['raster', 'css', 'dataset', 'service'] },
7
+ id: { type: 'string', pattern: '^([\\d\\w._-]+)$' },
8
+ },
9
+ },
10
+ body: {
11
+ type: 'object',
12
+ // additionalProperties: false,
13
+ properties: {
14
+ geom: {
15
+ type: 'object',
16
+ properties: {
17
+ type: { type: 'string', enum: ['Point', 'LineString', 'Polygon'] },
18
+ coordinates: { type: 'array' },
19
+ },
20
+ required: ['type', 'coordinates'],
21
+ },
22
+ description: { type: 'string' },
23
+ group_id: { type: 'string' },
24
+ keywords: {
25
+ type: 'array',
26
+ items: { type: 'string' },
27
+ },
28
+ is_public: { type: 'boolean' },
29
+ is_active: { type: 'boolean' },
30
+ service_key: { type: 'string' },
31
+ producer: { type: 'string' },
32
+ category: { type: 'string' },
33
+ license: { type: 'string' },
34
+ year: { type: 'string' },
35
+ service_url: { type: 'string' },
36
+ metadata_url: { type: 'string' },
37
+ thumbnail_url: { type: 'string' },
38
+ query: { type: 'string' },
39
+ },
40
+ },
41
+ };
42
+
43
+ export const metadataXMLSchema = {
44
+ params: {
45
+ type: 'object',
46
+ required: ['id'],
47
+ properties: {
48
+ id: { type: 'string', pattern: '^([\\d\\w._-]+)$' },
49
+ },
50
+ },
51
+ };
52
+
53
+ export default null;
@@ -1,117 +1,117 @@
1
- import { BadRequestError, NotFoundError } from '@opengis/fastify-table/errors.js';
2
- import {
3
- pgClients, handlebars, getMeta, getTemplate, getFilterSQL,
4
- } from '@opengis/fastify-table/utils.js';
5
-
6
- const columnType = {
7
- text: 'text',
8
- date: 'date',
9
- bool: 'yes/no',
10
- numeric: 'number',
11
- integer: 'number',
12
- 'timestamp without time zone': 'date',
13
- 'timestamp with time zone': 'date',
14
- };
15
-
16
- export default async function mapInfoPoint({ x, y, layers, index = 0, sql }, pg = pgClients.client) {
17
- const time = Date.now();
18
-
19
- if (!x || !y || !layers) {
20
- throw BadRequestError('not enough query params: x, y, layers are required');
21
- }
22
-
23
- const rows = pg?.pk?.['gis.ogc_service'] ? await pg.query('select * from gis.ogc_service WHERE enabled and table_name is not null and ogc_service_id = any($1)', [layers.split(',')]).then(r => r.rows || []) : [];
24
-
25
- if (!rows.length) {
26
- throw NotFoundError('layers not found');
27
- }
28
-
29
- const args = [];
30
-
31
- // 30, 50
32
- args.push(x);
33
- args.push(y);
34
-
35
- const srids = pg.queryCache ? await pg.queryCache('select json_agg(srid) as srids from spatial_ref_sys').then(r => r.rows?.[0]?.srids || {}) : {};
36
-
37
- await Promise.all(rows.map(async (layer, idx) => {
38
- const { table_name: source, ogc_service_id: layerId } = layer;
39
- const loadTable = await getTemplate('table', source);
40
- const meta = await getMeta({ pg, table: loadTable?.table || source });
41
- const { geom = 'geom' } = meta || {};
42
- const { table = source, columns = meta?.columns } = loadTable || {};
43
- const { srid, x } = await pg.query(`select st_srid(${geom}) as srid, st_x(st_pointonsurface(${geom})) as x from ${table} where geom is not null limit 1`).then(r => r.rows?.[0] || {});
44
-
45
- const cls = columns
46
- ?.filter(el => el.name && el.data)
47
- ?.reduce?.((acc, curr) => ({ ...acc, [curr.name]: curr.data }), {});
48
-
49
- const pk = pg.pk?.[table] || loadTable?.key;
50
-
51
- const { optimizedSQL } = await getFilterSQL({ pg, table: source, query: layer?.query });
52
-
53
- Object.assign(layer, {
54
- layer: (layerId || idx.toString())?.replace?.(/'/g, "''"),
55
- table,
56
- pk,
57
- cls,
58
- geomColumn: srid === 4326 ? geom : `st_transform(${geom},4326)`,
59
- optimizedSQL,
60
- srid,
61
- step: srids?.includes?.(srid - 0) && srid !== 4326 && x > 100 ? 10 : 0.0002,
62
- });
63
- }));
64
-
65
- const unique = rows.filter((el, idx, arr) => el.table && arr.map((item) => item.table).indexOf(el.table) === idx);
66
-
67
- const qList = unique.map((el) => ({
68
- query: `select ${el.pk}::text as pk, '${el.layer}' as layer, '${el.table}' as table,
69
- row_to_json(t) as data,
70
- st_distance(${el.geomColumn}, st_setsrid(st_makepoint($1,$2),4326)) as distance,
71
- st_asgeojson(${el.geomColumn})::json as geom from (${el.optimizedSQL}) t
72
- where 1=1`,
73
- queryCount: `select 1 from (${el.optimizedSQL})t where 1=1`,
74
- where: `${el.geomColumn} && st_setsrid(st_makepoint($1,$2),4326)`,
75
- }));
76
-
77
- const q = qList.map(el => `${el.query} and ${el.where}`).join(' union all ').concat(` order by distance limit 1 offset $3::bigint`);
78
-
79
- const qCount = qList.map(el => `${el.queryCount} and ${el.where}`).join(' union all ');
80
-
81
- if (sql === 1 && process.platform === 'win32') return q;
82
- if (sql === 2 && process.platform === 'win32') return qCount;
83
-
84
- const count = await pg.query(qCount, args).then(el => el.rowCount);
85
-
86
- const row = await pg.query(q, args.concat([Math.max(+index || 0, 0)])).then(r => r.rows?.[0]);
87
-
88
- if (!row) {
89
- throw NotFoundError('object not found');
90
- }
91
-
92
- const columns = row.table ? await getMeta({ pg, table: row.table }).then(r => r.columns || []) : [];
93
- const fields = columns.map(({ name, dataTypeID, title }) => ({ name, type: columnType[pg.pgType?.[dataTypeID] || 'text'], label: title || name }));
94
-
95
- const htmlTemplate = pg?.pk?.['admin.templates'] && row.layer && false
96
- ? await pg.query('select body from admin.templates where name=$1 limit 1', [row.layer]).then(r => r.rows?.[0]?.body)
97
- : rows.find(el => el.ogc_service_id === row.layer)?.html;
98
-
99
- const html = await handlebars.compile(htmlTemplate || 'template not found')(row.data);
100
-
101
- const res = {
102
- time: Date.now() - time,
103
- index,
104
- count,
105
- data: {
106
- layer: row.layer,
107
- geom: row.geom,
108
- id: row.pk,
109
- distance: row.distance,
110
- data: row.data,
111
- },
112
- fields,
113
- html,
114
- };
115
-
116
- return res;
117
- }
1
+ import { BadRequestError, NotFoundError } from '@opengis/fastify-table/errors.js';
2
+ import {
3
+ pgClients, handlebars, getMeta, getTemplate, getFilterSQL,
4
+ } from '@opengis/fastify-table/utils.js';
5
+
6
+ const columnType = {
7
+ text: 'text',
8
+ date: 'date',
9
+ bool: 'yes/no',
10
+ numeric: 'number',
11
+ integer: 'number',
12
+ 'timestamp without time zone': 'date',
13
+ 'timestamp with time zone': 'date',
14
+ };
15
+
16
+ export default async function mapInfoPoint({ x, y, layers, index = 0, sql }, pg = pgClients.client) {
17
+ const time = Date.now();
18
+
19
+ if (!x || !y || !layers) {
20
+ throw BadRequestError('not enough query params: x, y, layers are required');
21
+ }
22
+
23
+ const rows = pg?.pk?.['gis.ogc_service'] ? await pg.query('select * from gis.ogc_service WHERE enabled and table_name is not null and ogc_service_id = any($1)', [layers.split(',')]).then(r => r.rows || []) : [];
24
+
25
+ if (!rows.length) {
26
+ throw NotFoundError('layers not found');
27
+ }
28
+
29
+ const args = [];
30
+
31
+ // 30, 50
32
+ args.push(x);
33
+ args.push(y);
34
+
35
+ const srids = pg.queryCache ? await pg.queryCache('select json_agg(srid) as srids from spatial_ref_sys').then(r => r.rows?.[0]?.srids || {}) : {};
36
+
37
+ await Promise.all(rows.map(async (layer, idx) => {
38
+ const { table_name: source, ogc_service_id: layerId } = layer;
39
+ const loadTable = await getTemplate('table', source);
40
+ const meta = await getMeta({ pg, table: loadTable?.table || source });
41
+ const { geom = 'geom' } = meta || {};
42
+ const { table = source, columns = meta?.columns } = loadTable || {};
43
+ const { srid, x } = await pg.query(`select st_srid(${geom}) as srid, st_x(st_pointonsurface(${geom})) as x from ${table} where geom is not null limit 1`).then(r => r.rows?.[0] || {});
44
+
45
+ const cls = columns
46
+ ?.filter(el => el.name && el.data)
47
+ ?.reduce?.((acc, curr) => ({ ...acc, [curr.name]: curr.data }), {});
48
+
49
+ const pk = pg.pk?.[table] || loadTable?.key;
50
+
51
+ const { optimizedSQL } = await getFilterSQL({ pg, table: source, query: layer?.query });
52
+
53
+ Object.assign(layer, {
54
+ layer: (layerId || idx.toString())?.replace?.(/'/g, "''"),
55
+ table,
56
+ pk,
57
+ cls,
58
+ geomColumn: srid === 4326 ? geom : `st_transform(${geom},4326)`,
59
+ optimizedSQL,
60
+ srid,
61
+ step: srids?.includes?.(srid - 0) && srid !== 4326 && x > 100 ? 10 : 0.0002,
62
+ });
63
+ }));
64
+
65
+ const unique = rows.filter((el, idx, arr) => el.table && arr.map((item) => item.table).indexOf(el.table) === idx);
66
+
67
+ const qList = unique.map((el) => ({
68
+ query: `select ${el.pk}::text as pk, '${el.layer}' as layer, '${el.table}' as table,
69
+ row_to_json(t) as data,
70
+ st_distance(${el.geomColumn}, st_setsrid(st_makepoint($1,$2),4326)) as distance,
71
+ st_asgeojson(${el.geomColumn})::json as geom from (${el.optimizedSQL}) t
72
+ where 1=1`,
73
+ queryCount: `select 1 from (${el.optimizedSQL})t where 1=1`,
74
+ where: `${el.geomColumn} && st_setsrid(st_makepoint($1,$2),4326)`,
75
+ }));
76
+
77
+ const q = qList.map(el => `${el.query} and ${el.where}`).join(' union all ').concat(` order by distance limit 1 offset $3::bigint`);
78
+
79
+ const qCount = qList.map(el => `${el.queryCount} and ${el.where}`).join(' union all ');
80
+
81
+ if (sql === 1 && process.platform === 'win32') return q;
82
+ if (sql === 2 && process.platform === 'win32') return qCount;
83
+
84
+ const count = await pg.query(qCount, args).then(el => el.rowCount);
85
+
86
+ const row = await pg.query(q, args.concat([Math.max(+index || 0, 0)])).then(r => r.rows?.[0]);
87
+
88
+ if (!row) {
89
+ throw NotFoundError('object not found');
90
+ }
91
+
92
+ const columns = row.table ? await getMeta({ pg, table: row.table }).then(r => r.columns || []) : [];
93
+ const fields = columns.map(({ name, dataTypeID, title }) => ({ name, type: columnType[pg.pgType?.[dataTypeID] || 'text'], label: title || name }));
94
+
95
+ const htmlTemplate = pg?.pk?.['admin.templates'] && row.layer && false
96
+ ? await pg.query('select body from admin.templates where name=$1 limit 1', [row.layer]).then(r => r.rows?.[0]?.body)
97
+ : rows.find(el => el.ogc_service_id === row.layer)?.html;
98
+
99
+ const html = await handlebars.compile(htmlTemplate || 'template not found')(row.data);
100
+
101
+ const res = {
102
+ time: Date.now() - time,
103
+ index,
104
+ count,
105
+ data: {
106
+ layer: row.layer,
107
+ geom: row.geom,
108
+ id: row.pk,
109
+ distance: row.distance,
110
+ data: row.data,
111
+ },
112
+ fields,
113
+ html,
114
+ };
115
+
116
+ return res;
117
+ }
@@ -1,21 +1,21 @@
1
- import mapInfoPoint from './functions/map.info.point.js';
2
-
3
- import {
4
- mapInfoPointSchema,
5
- } from './ogc.schema.js';
6
-
7
- const publicParams = { config: { policy: 'L0', package: 'gis' } };
8
-
9
- async function route(app) {
10
- app.get('/map-info-point', { ...publicParams, schema: mapInfoPointSchema }, async ({ query, pg }) => {
11
- const result = await mapInfoPoint({
12
- x: query.x,
13
- y: query.y,
14
- layers: query.layers,
15
- index: query.index,
16
- sql: query.sql
17
- }, pg);
18
- return result;
19
- });
20
- }
21
- export default route;
1
+ import mapInfoPoint from './functions/map.info.point.js';
2
+
3
+ import {
4
+ mapInfoPointSchema,
5
+ } from './ogc.schema.js';
6
+
7
+ const publicParams = { config: { policy: 'L0', package: 'gis' } };
8
+
9
+ async function route(app) {
10
+ app.get('/map-info-point', { ...publicParams, schema: mapInfoPointSchema }, async ({ query, pg }) => {
11
+ const result = await mapInfoPoint({
12
+ x: query.x,
13
+ y: query.y,
14
+ layers: query.layers,
15
+ index: query.index,
16
+ sql: query.sql
17
+ }, pg);
18
+ return result;
19
+ });
20
+ }
21
+ export default route;