@opengis/gis 0.2.176 → 0.2.178
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/README.md +181 -181
- package/dist/{CardIcon-c1Q2M3wQ.js → CardIcon-CMRD1LLh.js} +1 -1
- package/dist/{EntityTablePage-B5gpkH4S.js → EntityTablePage-XNNCltAN.js} +2 -2
- package/dist/{ExtentOutlineLayer.vue_vue_type_script_setup_true_lang-DnGSvmMU.js → ExtentOutlineLayer.vue_vue_type_script_setup_true_lang-BqUjKTDY.js} +1 -1
- package/dist/{HeaderActions.vue_vue_type_script_setup_true_lang-C2B61JP6.js → HeaderActions.vue_vue_type_script_setup_true_lang-BXQ3hKwa.js} +1 -1
- package/dist/{MapSettings-6-Xru5Q8.js → MapSettings-P3h-vHn3.js} +2 -2
- package/dist/{RastersTablePage-CXNOcTy-.js → RastersTablePage-DnhGZLiH.js} +2 -2
- package/dist/{cartocss-BFVqWvfP.js → cartocss-BkrOeQg4.js} +6 -6
- package/dist/{import-utils-uxk4LdUJ.js → import-utils-BCATsbB5.js} +1 -1
- package/dist/{index-CahlV-Xs.js → index-cUagVqgA.js} +39 -39
- package/dist/index.css +1 -1
- package/dist/index.js +1 -1
- package/dist/index.umd.cjs +5 -5
- package/dist/{raster-CEi56f0P.js → raster-CP0tUp3j.js} +3 -3
- package/dist/{register-NFAGBNa3.js → register-Cr-uQcby.js} +3 -3
- package/dist/{service-BYspag8U.js → service-DwJaKrOd.js} +6 -6
- package/dist/{vs-datatable-CHcBr6zy.js → vs-datatable-B9WoVk-b.js} +2 -2
- package/module/gis/cls/service_type.json +42 -42
- package/module/gis/form/gis.registers.form.json +127 -127
- package/module/test/map/addr.json +302 -302
- package/module/test/map/addr1.yml +23 -23
- package/module/test/select/address.str_id.sql +3 -3
- package/package.json +77 -77
- package/plugin.js +64 -64
- package/server/migrations/array_intersect.sql +13 -13
- package/server/migrations/cartocss.sql +27 -27
- package/server/migrations/group_list.sql +74 -74
- package/server/migrations/maps.sql +30 -30
- package/server/migrations/metadata.sql +415 -415
- package/server/migrations/ogc.sql +106 -106
- package/server/migrations/rasters.sql +265 -265
- package/server/migrations/services.sql +247 -247
- package/server/migrations/services_users_rel.sql +22 -22
- package/server/migrations/widgets.sql +20 -20
- package/server/plugins/crons.js +21 -21
- package/server/plugins/mapnik/funcs/checkRasterFile.js +107 -107
- package/server/plugins/mapnik/funcs/mapnik.js +151 -151
- package/server/plugins/mapnik/funcs/rootFolder.mjs +8 -8
- package/server/plugins/mapnik/map.proto +437 -437
- package/server/plugins/vite.js +74 -74
- package/server/routes/cartocss/cartocss.route.js +31 -31
- package/server/routes/cartocss/cartocss.route.test.js +78 -78
- package/server/routes/cartocss/cartocss.schema.js +73 -73
- package/server/routes/cartocss/functions/add.cartocss.js +39 -39
- package/server/routes/cartocss/functions/get.cartocss.js +57 -57
- package/server/routes/gis/functions/checkXML.js +107 -107
- package/server/routes/gis/functions/dashboard.js +24 -24
- package/server/routes/gis/gis.route.js +26 -26
- package/server/routes/gis/gis.route.test.js +33 -33
- package/server/routes/map/functions/clearTiles.js +35 -35
- package/server/routes/map/functions/geojson.js +187 -187
- package/server/routes/map/functions/gis.convert.js +65 -65
- package/server/routes/map/functions/gis.icon.js +220 -220
- package/server/routes/map/functions/jsonData.js +206 -206
- package/server/routes/map/functions/layerList.js +102 -102
- package/server/routes/map/functions/map.js +122 -122
- package/server/routes/map/functions/mapCatalog.js +72 -72
- package/server/routes/map/functions/mapCatalogAttribute.js +53 -53
- package/server/routes/map/functions/mapFeatures.js +133 -133
- package/server/routes/map/functions/mapFormat.js +232 -232
- package/server/routes/map/functions/mapTiles.js +162 -162
- package/server/routes/map/functions/maps.js +15 -15
- package/server/routes/map/functions/marker_icon.js +43 -43
- package/server/routes/map/functions/parseGeoFile.js +85 -85
- package/server/routes/map/functions/pointHeight.js +51 -51
- package/server/routes/map/functions/vtile.js +174 -174
- package/server/routes/map/functions/vtile1.js +185 -185
- package/server/routes/map/map.route.js +280 -280
- package/server/routes/map/map.route.test.js +503 -503
- package/server/routes/map/map.schema.js +356 -356
- package/server/routes/map/pin/circle1.svg +76 -76
- package/server/routes/map/pin/circle2.svg +18 -18
- package/server/routes/map/pin/none.svg +12 -12
- package/server/routes/map/pin/pin.svg +14 -14
- package/server/routes/map/pin/pin1.svg +16 -16
- package/server/routes/map/pin/pin2.svg +7 -7
- package/server/routes/map/pin/pin3.svg +34 -34
- package/server/routes/map/pin/pin4.svg +14 -14
- package/server/routes/map/pin/pin5.svg +7 -7
- package/server/routes/map/pin/pin6.svg +12 -12
- package/server/routes/map/pin/pin7.svg +12 -12
- package/server/routes/mapnik/functions/cartoBounds.js +32 -32
- package/server/routes/mapnik/functions/clearTiles.js +103 -103
- package/server/routes/mapnik/functions/convertBoundToTile.js +27 -27
- package/server/routes/mapnik/functions/createXml.js +76 -76
- package/server/routes/mapnik/functions/createXmlMulti.js +72 -72
- package/server/routes/mapnik/functions/fileSearch.js +35 -35
- package/server/routes/mapnik/functions/fileStat.js +28 -28
- package/server/routes/mapnik/functions/pretile.js +138 -138
- package/server/routes/mapnik/functions/rasterInfo.js +66 -66
- package/server/routes/mapnik/functions/readDir.js +22 -22
- package/server/routes/mapnik/functions/rtile.js +164 -164
- package/server/routes/mapnik/functions/uploadRaster.js +152 -152
- package/server/routes/mapnik/functions/uploadXML.js +140 -140
- package/server/routes/mapnik/mapnik.route.js +102 -102
- package/server/routes/mapnik/mapnik.route.test.js +370 -370
- package/server/routes/mapnik/mapnik.schema.mjs +195 -195
- package/server/routes/mapnik.prefixless/functions/mapnikLogger.js +31 -31
- package/server/routes/mapnik.prefixless/functions/mapnikStat.js +21 -21
- package/server/routes/mapnik.prefixless/mapnik.prefixless.route.js +20 -20
- package/server/routes/mapnik.prefixless/mapnik.prefixless.route.test.js +91 -91
- package/server/routes/mapnik.prefixless/mapnik.prefixless.schema.mjs +27 -27
- package/server/routes/maps/functions/add.map.js +42 -42
- package/server/routes/maps/functions/del.map.js +17 -17
- package/server/routes/maps/functions/get.map.js +119 -119
- package/server/routes/maps/maps.route.js +58 -58
- package/server/routes/maps/maps.route.test.js +231 -231
- package/server/routes/maps/maps.schema.js +9 -9
- package/server/routes/metadata/functions/editMetadata.js +35 -35
- package/server/routes/metadata/functions/metadataXML.js +19 -19
- package/server/routes/metadata/metadata.route.js +26 -26
- package/server/routes/metadata/metadata.route.test.js +46 -46
- package/server/routes/metadata/metadata.schema.js +53 -53
- package/server/routes/ogc/functions/map.info.point.js +117 -117
- package/server/routes/ogc/ogc.route.js +21 -21
- package/server/routes/ogc/ogc.route.test.js +53 -53
- package/server/routes/ogc/ogc.schema.js +16 -16
- package/server/routes/permissions/functions/catalog.permissions.edit.js +20 -20
- package/server/routes/permissions/functions/catalog.permissions.js +12 -12
- package/server/routes/permissions/functions/get.permissions.js +59 -59
- package/server/routes/permissions/functions/gis.catalog.js +80 -80
- package/server/routes/permissions/permissions.route.js +35 -35
- package/server/routes/permissions/permissions.route.test.js +35 -35
- package/server/routes/permissions/permissions.schema.js +43 -43
- package/server/routes/registers/functions/add.registry.js +37 -37
- package/server/routes/registers/functions/classifiers.js +100 -100
- package/server/routes/registers/functions/columns.js +3 -3
- package/server/routes/registers/functions/content.type.js +9 -9
- package/server/routes/registers/functions/del.registry.js +14 -14
- package/server/routes/registers/functions/get.info.js +93 -93
- package/server/routes/registers/functions/getFilterSQLParametrized/formatValue.js +312 -0
- package/server/routes/registers/functions/getFilterSQLParametrized/getFilterQuery.js +126 -0
- package/server/routes/registers/functions/getFilterSQLParametrized/getRangeQuery.js +353 -0
- package/server/routes/registers/functions/getFilterSQLParametrized/index.js +81 -0
- package/server/routes/registers/functions/getTableColumnMeta.js +125 -0
- package/server/routes/registers/functions/gis.export.js +159 -159
- package/server/routes/registers/functions/gis.registry.js +71 -71
- package/server/routes/registers/functions/gis.registry.list.js +61 -61
- package/server/routes/registers/functions/gis.suggest.js +275 -0
- package/server/routes/registers/functions/handleRegistryRequest.js +175 -147
- package/server/routes/registers/functions/map.registry.js +87 -87
- package/server/routes/registers/registers.route.js +91 -80
- package/server/routes/registers/registers.route.test.js +173 -144
- package/server/routes/registers/registers.schema.js +275 -246
- package/server/routes/root.mjs +3 -3
- package/server/routes/services/functions/add.service.js +62 -62
- package/server/routes/services/functions/create.route.js +93 -93
- package/server/routes/services/functions/del.service.js +12 -12
- package/server/routes/services/functions/get.layer.geom.js +27 -27
- package/server/routes/services/functions/get.service.users.js +76 -76
- package/server/routes/services/functions/get.services.col.js +34 -34
- package/server/routes/services/functions/get.services.js +89 -89
- package/server/routes/services/functions/legend.auto.js +77 -77
- package/server/routes/services/services.route.js +76 -76
- package/server/routes/services/services.route.test.js +167 -167
- package/server/routes/services/services.schema.js +285 -278
- package/server/routes/widgets/functions/add.widget.js +38 -38
- package/server/routes/widgets/functions/del.widget.js +17 -17
- package/server/routes/widgets/functions/get.widget.js +41 -41
- package/server/routes/widgets/widgets.route.js +61 -61
- package/server/routes/widgets/widgets.route.test.js +144 -144
- package/server/routes/widgets/widgets.schema.js +24 -24
- package/server/shared/listFiles.js +14 -14
- package/utils.js +13 -13
package/server/plugins/vite.js
CHANGED
|
@@ -1,74 +1,74 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { createServer } from 'vite';
|
|
4
|
-
|
|
5
|
-
// import { config } from '@opengis/fastify-table/utils.js';
|
|
6
|
-
|
|
7
|
-
const isProduction = process.env.NODE_ENV === 'production';
|
|
8
|
-
|
|
9
|
-
console.log({ isProduction });
|
|
10
|
-
|
|
11
|
-
async function plugin(fastify, opts) {
|
|
12
|
-
const viteServer = !isProduction ? await createServer({
|
|
13
|
-
root: 'admin',
|
|
14
|
-
server: {
|
|
15
|
-
middlewareMode: true,
|
|
16
|
-
},
|
|
17
|
-
}) : null;
|
|
18
|
-
|
|
19
|
-
if (!isProduction) {
|
|
20
|
-
const dir1 = process.cwd();
|
|
21
|
-
viteServer.watcher.add(dir1);
|
|
22
|
-
viteServer.watcher.on('all', (d, t) => {
|
|
23
|
-
if (!t.includes('module')) return;
|
|
24
|
-
console.log(d, t);
|
|
25
|
-
viteServer.ws.send({ type: 'full-reload' });
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
// this is middleware for vite's dev server
|
|
29
|
-
fastify.addHook('onRequest', async (req, reply) => {
|
|
30
|
-
const { user } = req.session?.passport || {};
|
|
31
|
-
// console.log(req.url);
|
|
32
|
-
|
|
33
|
-
const next = () => new Promise((resolve) => {
|
|
34
|
-
viteServer.middlewares(req.raw, reply.raw, () => resolve());
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
await next();
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
async function staticFile(req, reply) {
|
|
42
|
-
const assetsDir = 'admin/dist';
|
|
43
|
-
|
|
44
|
-
const filePathDist = path.join(assetsDir, req.url.replace('/public/', '/'));
|
|
45
|
-
const filePathAssets = path.join('assets', req.url.replace('/assets', ''));
|
|
46
|
-
|
|
47
|
-
const filePath = fs.existsSync(filePathDist) ? filePathDist : filePathAssets; // check dist or assets
|
|
48
|
-
const ext = path.extname(filePath);
|
|
49
|
-
|
|
50
|
-
if (!fs.existsSync(filePath)) return { status: 404, message: 'not found' };
|
|
51
|
-
const mime = {
|
|
52
|
-
'.js': 'text/javascript', '.css': 'text/css', '.woff2': 'application/font-woff', '.png': 'image/png', '.svg': 'image/svg+xml', '.jpg': 'image/jpg',
|
|
53
|
-
}[ext];
|
|
54
|
-
reply.headers({ 'Cache-control': 'max-age=3600, public', 'Content-Encoding': 'identity' });
|
|
55
|
-
|
|
56
|
-
const stream = fs.createReadStream(filePath);
|
|
57
|
-
return mime ? reply.type(mime).send(stream) : stream;
|
|
58
|
-
}
|
|
59
|
-
fastify.get('/assets/*', staticFile);
|
|
60
|
-
fastify.get('/public/*', staticFile);
|
|
61
|
-
|
|
62
|
-
fastify.get('*', async (req, reply) => {
|
|
63
|
-
const { user } = req.session?.passport || {};
|
|
64
|
-
|
|
65
|
-
if (!user && req.url.split('?')[0] !== '/login') {
|
|
66
|
-
return reply.redirect(`/login?redirect=${req.url}`);
|
|
67
|
-
}
|
|
68
|
-
if (!isProduction) return null; // admin vite
|
|
69
|
-
const stream = fs.createReadStream('admin/dist/index.html');
|
|
70
|
-
return reply.type('text/html').send(stream);
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export default plugin;
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { createServer } from 'vite';
|
|
4
|
+
|
|
5
|
+
// import { config } from '@opengis/fastify-table/utils.js';
|
|
6
|
+
|
|
7
|
+
const isProduction = process.env.NODE_ENV === 'production';
|
|
8
|
+
|
|
9
|
+
console.log({ isProduction });
|
|
10
|
+
|
|
11
|
+
async function plugin(fastify, opts) {
|
|
12
|
+
const viteServer = !isProduction ? await createServer({
|
|
13
|
+
root: 'admin',
|
|
14
|
+
server: {
|
|
15
|
+
middlewareMode: true,
|
|
16
|
+
},
|
|
17
|
+
}) : null;
|
|
18
|
+
|
|
19
|
+
if (!isProduction) {
|
|
20
|
+
const dir1 = process.cwd();
|
|
21
|
+
viteServer.watcher.add(dir1);
|
|
22
|
+
viteServer.watcher.on('all', (d, t) => {
|
|
23
|
+
if (!t.includes('module')) return;
|
|
24
|
+
console.log(d, t);
|
|
25
|
+
viteServer.ws.send({ type: 'full-reload' });
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
// this is middleware for vite's dev server
|
|
29
|
+
fastify.addHook('onRequest', async (req, reply) => {
|
|
30
|
+
const { user } = req.session?.passport || {};
|
|
31
|
+
// console.log(req.url);
|
|
32
|
+
|
|
33
|
+
const next = () => new Promise((resolve) => {
|
|
34
|
+
viteServer.middlewares(req.raw, reply.raw, () => resolve());
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
await next();
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function staticFile(req, reply) {
|
|
42
|
+
const assetsDir = 'admin/dist';
|
|
43
|
+
|
|
44
|
+
const filePathDist = path.join(assetsDir, req.url.replace('/public/', '/'));
|
|
45
|
+
const filePathAssets = path.join('assets', req.url.replace('/assets', ''));
|
|
46
|
+
|
|
47
|
+
const filePath = fs.existsSync(filePathDist) ? filePathDist : filePathAssets; // check dist or assets
|
|
48
|
+
const ext = path.extname(filePath);
|
|
49
|
+
|
|
50
|
+
if (!fs.existsSync(filePath)) return { status: 404, message: 'not found' };
|
|
51
|
+
const mime = {
|
|
52
|
+
'.js': 'text/javascript', '.css': 'text/css', '.woff2': 'application/font-woff', '.png': 'image/png', '.svg': 'image/svg+xml', '.jpg': 'image/jpg',
|
|
53
|
+
}[ext];
|
|
54
|
+
reply.headers({ 'Cache-control': 'max-age=3600, public', 'Content-Encoding': 'identity' });
|
|
55
|
+
|
|
56
|
+
const stream = fs.createReadStream(filePath);
|
|
57
|
+
return mime ? reply.type(mime).send(stream) : stream;
|
|
58
|
+
}
|
|
59
|
+
fastify.get('/assets/*', staticFile);
|
|
60
|
+
fastify.get('/public/*', staticFile);
|
|
61
|
+
|
|
62
|
+
fastify.get('*', async (req, reply) => {
|
|
63
|
+
const { user } = req.session?.passport || {};
|
|
64
|
+
|
|
65
|
+
if (!user && req.url.split('?')[0] !== '/login') {
|
|
66
|
+
return reply.redirect(`/login?redirect=${req.url}`);
|
|
67
|
+
}
|
|
68
|
+
if (!isProduction) return null; // admin vite
|
|
69
|
+
const stream = fs.createReadStream('admin/dist/index.html');
|
|
70
|
+
return reply.type('text/html').send(stream);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export default plugin;
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import getCartocss from './functions/get.cartocss.js';
|
|
2
|
-
import addCartocss from './functions/add.cartocss.js';
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
getCartocssSchema,
|
|
6
|
-
addCartocssSchema,
|
|
7
|
-
} from './cartocss.schema.js';
|
|
8
|
-
|
|
9
|
-
const privateParams = { config: { policy: 'L1', package: 'gis' } };
|
|
10
|
-
const publicParams = { config: { policy: 'L0', package: 'gis' } };
|
|
11
|
-
|
|
12
|
-
async function route(app) {
|
|
13
|
-
app.get('/gis-css/:id', { ...publicParams, schema: getCartocssSchema }, async ({ params, query, user, pg }) => {
|
|
14
|
-
const result = await getCartocss({
|
|
15
|
-
id: params.id,
|
|
16
|
-
sql: query.sql,
|
|
17
|
-
nocache: query.nocache,
|
|
18
|
-
isAdmin: user?.user_type?.includes?.('admin')
|
|
19
|
-
}, pg);
|
|
20
|
-
return result;
|
|
21
|
-
});
|
|
22
|
-
app.post('/gis-css/:id', { ...privateParams, schema: addCartocssSchema }, async ({ params, body, user, pg }) => {
|
|
23
|
-
const result = await addCartocss({
|
|
24
|
-
id: params.id,
|
|
25
|
-
body,
|
|
26
|
-
uid: user?.uid,
|
|
27
|
-
}, pg);
|
|
28
|
-
return result;
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
export default route;
|
|
1
|
+
import getCartocss from './functions/get.cartocss.js';
|
|
2
|
+
import addCartocss from './functions/add.cartocss.js';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
getCartocssSchema,
|
|
6
|
+
addCartocssSchema,
|
|
7
|
+
} from './cartocss.schema.js';
|
|
8
|
+
|
|
9
|
+
const privateParams = { config: { policy: 'L1', package: 'gis' } };
|
|
10
|
+
const publicParams = { config: { policy: 'L0', package: 'gis' } };
|
|
11
|
+
|
|
12
|
+
async function route(app) {
|
|
13
|
+
app.get('/gis-css/:id', { ...publicParams, schema: getCartocssSchema }, async ({ params, query, user, pg }) => {
|
|
14
|
+
const result = await getCartocss({
|
|
15
|
+
id: params.id,
|
|
16
|
+
sql: query.sql,
|
|
17
|
+
nocache: query.nocache,
|
|
18
|
+
isAdmin: user?.user_type?.includes?.('admin')
|
|
19
|
+
}, pg);
|
|
20
|
+
return result;
|
|
21
|
+
});
|
|
22
|
+
app.post('/gis-css/:id', { ...privateParams, schema: addCartocssSchema }, async ({ params, body, user, pg }) => {
|
|
23
|
+
const result = await addCartocss({
|
|
24
|
+
id: params.id,
|
|
25
|
+
body,
|
|
26
|
+
uid: user?.uid,
|
|
27
|
+
}, pg);
|
|
28
|
+
return result;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
export default route;
|
|
@@ -1,79 +1,79 @@
|
|
|
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
|
-
const user = { id: '2', type: 'admin' };
|
|
8
|
-
|
|
9
|
-
let pg;
|
|
10
|
-
|
|
11
|
-
beforeAll(async () => {
|
|
12
|
-
await build();
|
|
13
|
-
|
|
14
|
-
pg = await getPGAsync();
|
|
15
|
-
|
|
16
|
-
await cleanUp('before');
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
afterAll(async () => {
|
|
20
|
-
await cleanUp('after');
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
const testId = 'testCss';
|
|
24
|
-
|
|
25
|
-
const cleanUp = async (when) => {
|
|
26
|
-
if (!pg) return;
|
|
27
|
-
const rowCount = await pg.query('delete from gis.cartocss where cartocss_id=$1', [testId]).then(r => r.rowCount || 0);
|
|
28
|
-
const rowCount3 = await pg.query('delete from gis.metadata where metadata_id=$1', [testId]).then(r => r.rowCount || 0);
|
|
29
|
-
console.log(`clean up finished: ${when}`, rowCount, rowCount3);
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
describe('cartocss api', () => {
|
|
33
|
-
test('POST /gis-css/:id returns 200', async () => {
|
|
34
|
-
const payload = {
|
|
35
|
-
source_path: 'test',
|
|
36
|
-
config: { test: 1 },
|
|
37
|
-
style: '#test { color: red; }'
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
await pg.query('insert into gis.cartocss(cartocss_id,name) values($1,$2)', [testId, 'unit-test']).catch(err => console.error(err));
|
|
41
|
-
const res = await injectWithHeaders({
|
|
42
|
-
method: 'POST',
|
|
43
|
-
url: `/api/gis-css/${testId}`,
|
|
44
|
-
payload,
|
|
45
|
-
headers: { uid: user.id, user_type: user.type }
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
expect(res.statusCode).toBe(200);
|
|
49
|
-
expect(res.body).toHaveProperty('message');
|
|
50
|
-
expect(res.body).toHaveProperty('code');
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
test('POST /gis-metadata/:type/:id returns 200', async () => {
|
|
54
|
-
const res = await injectWithHeaders({
|
|
55
|
-
method: 'POST',
|
|
56
|
-
url: `/api/gis-metadata/css/${testId}`,
|
|
57
|
-
payload: {
|
|
58
|
-
layer_id: testId
|
|
59
|
-
},
|
|
60
|
-
headers: { uid: user.id, user_type: user.type }
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
expect(res.statusCode).toBe(200);
|
|
64
|
-
expect(res.body).toHaveProperty('metadata_id');
|
|
65
|
-
expect(res.body.metadata_id).toBe(testId);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
test('GET /gis-css/:id returns 200', async () => {
|
|
69
|
-
const res = await injectWithHeaders({
|
|
70
|
-
url: `/api/gis-css/${testId}`,
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
expect(res.statusCode).toBe(200);
|
|
74
|
-
expect(res.body).toHaveProperty('source_path');
|
|
75
|
-
expect(res.body).toHaveProperty('cartocss_id');
|
|
76
|
-
expect(res.body).toHaveProperty('cartocss_key');
|
|
77
|
-
expect(res.body).toHaveProperty('url');
|
|
78
|
-
});
|
|
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
|
+
const user = { id: '2', type: 'admin' };
|
|
8
|
+
|
|
9
|
+
let pg;
|
|
10
|
+
|
|
11
|
+
beforeAll(async () => {
|
|
12
|
+
await build();
|
|
13
|
+
|
|
14
|
+
pg = await getPGAsync();
|
|
15
|
+
|
|
16
|
+
await cleanUp('before');
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
afterAll(async () => {
|
|
20
|
+
await cleanUp('after');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const testId = 'testCss';
|
|
24
|
+
|
|
25
|
+
const cleanUp = async (when) => {
|
|
26
|
+
if (!pg) return;
|
|
27
|
+
const rowCount = await pg.query('delete from gis.cartocss where cartocss_id=$1', [testId]).then(r => r.rowCount || 0);
|
|
28
|
+
const rowCount3 = await pg.query('delete from gis.metadata where metadata_id=$1', [testId]).then(r => r.rowCount || 0);
|
|
29
|
+
console.log(`clean up finished: ${when}`, rowCount, rowCount3);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
describe('cartocss api', () => {
|
|
33
|
+
test('POST /gis-css/:id returns 200', async () => {
|
|
34
|
+
const payload = {
|
|
35
|
+
source_path: 'test',
|
|
36
|
+
config: { test: 1 },
|
|
37
|
+
style: '#test { color: red; }'
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
await pg.query('insert into gis.cartocss(cartocss_id,name) values($1,$2)', [testId, 'unit-test']).catch(err => console.error(err));
|
|
41
|
+
const res = await injectWithHeaders({
|
|
42
|
+
method: 'POST',
|
|
43
|
+
url: `/api/gis-css/${testId}`,
|
|
44
|
+
payload,
|
|
45
|
+
headers: { uid: user.id, user_type: user.type }
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
expect(res.statusCode).toBe(200);
|
|
49
|
+
expect(res.body).toHaveProperty('message');
|
|
50
|
+
expect(res.body).toHaveProperty('code');
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('POST /gis-metadata/:type/:id returns 200', async () => {
|
|
54
|
+
const res = await injectWithHeaders({
|
|
55
|
+
method: 'POST',
|
|
56
|
+
url: `/api/gis-metadata/css/${testId}`,
|
|
57
|
+
payload: {
|
|
58
|
+
layer_id: testId
|
|
59
|
+
},
|
|
60
|
+
headers: { uid: user.id, user_type: user.type }
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
expect(res.statusCode).toBe(200);
|
|
64
|
+
expect(res.body).toHaveProperty('metadata_id');
|
|
65
|
+
expect(res.body.metadata_id).toBe(testId);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('GET /gis-css/:id returns 200', async () => {
|
|
69
|
+
const res = await injectWithHeaders({
|
|
70
|
+
url: `/api/gis-css/${testId}`,
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
expect(res.statusCode).toBe(200);
|
|
74
|
+
expect(res.body).toHaveProperty('source_path');
|
|
75
|
+
expect(res.body).toHaveProperty('cartocss_id');
|
|
76
|
+
expect(res.body).toHaveProperty('cartocss_key');
|
|
77
|
+
expect(res.body).toHaveProperty('url');
|
|
78
|
+
});
|
|
79
79
|
});
|
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
const geometrySchema = {
|
|
2
|
-
|
|
3
|
-
type: "object",
|
|
4
|
-
required: ["type", "coordinates"],
|
|
5
|
-
properties: {
|
|
6
|
-
type: {
|
|
7
|
-
enum: [
|
|
8
|
-
"Point",
|
|
9
|
-
"LineString",
|
|
10
|
-
"Polygon",
|
|
11
|
-
"MultiPoint",
|
|
12
|
-
"MultiLineString",
|
|
13
|
-
"MultiPolygon",
|
|
14
|
-
],
|
|
15
|
-
},
|
|
16
|
-
coordinates: {
|
|
17
|
-
type: "array",
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const cssBodySchema = {
|
|
24
|
-
type: "object",
|
|
25
|
-
additionalProperties: true,
|
|
26
|
-
|
|
27
|
-
properties: {
|
|
28
|
-
id: { type: "string", pattern: '^([\\d\\w._-]+)$' },
|
|
29
|
-
name: { type: "string" },
|
|
30
|
-
group_id: { type: "string" },
|
|
31
|
-
cartocss_key: { type: "string" },
|
|
32
|
-
source_path: { type: "string" },
|
|
33
|
-
description: { type: ["string", "null"] },
|
|
34
|
-
card_table: { type: "string" },
|
|
35
|
-
card_columns: { type: "string" },
|
|
36
|
-
card_html: { type: "string" },
|
|
37
|
-
is_public: { type: "boolean" },
|
|
38
|
-
is_static: { type: "boolean" },
|
|
39
|
-
enabled: { type: "boolean" },
|
|
40
|
-
geom: geometrySchema,
|
|
41
|
-
},
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export const getCartocssSchema = {
|
|
45
|
-
params: {
|
|
46
|
-
type: 'object',
|
|
47
|
-
required: ['id'],
|
|
48
|
-
properties: {
|
|
49
|
-
id: { type: 'string', pattern: '^([\\d\\w._-]+)$' }
|
|
50
|
-
}
|
|
51
|
-
},
|
|
52
|
-
querystring: {
|
|
53
|
-
type: 'object',
|
|
54
|
-
additionalProperties: false,
|
|
55
|
-
properties: {
|
|
56
|
-
nocache: { type: 'number', enum: [1] },
|
|
57
|
-
sql: { type: 'number', enum: [1] },
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
export const addCartocssSchema = {
|
|
63
|
-
params: {
|
|
64
|
-
type: 'object',
|
|
65
|
-
required: ['id'],
|
|
66
|
-
properties: {
|
|
67
|
-
id: { type: 'string', pattern: '^([\\d\\w._-]+)$' }
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
body: cssBodySchema,
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
export default null;
|
|
1
|
+
const geometrySchema = {
|
|
2
|
+
|
|
3
|
+
type: "object",
|
|
4
|
+
required: ["type", "coordinates"],
|
|
5
|
+
properties: {
|
|
6
|
+
type: {
|
|
7
|
+
enum: [
|
|
8
|
+
"Point",
|
|
9
|
+
"LineString",
|
|
10
|
+
"Polygon",
|
|
11
|
+
"MultiPoint",
|
|
12
|
+
"MultiLineString",
|
|
13
|
+
"MultiPolygon",
|
|
14
|
+
],
|
|
15
|
+
},
|
|
16
|
+
coordinates: {
|
|
17
|
+
type: "array",
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const cssBodySchema = {
|
|
24
|
+
type: "object",
|
|
25
|
+
additionalProperties: true,
|
|
26
|
+
|
|
27
|
+
properties: {
|
|
28
|
+
id: { type: "string", pattern: '^([\\d\\w._-]+)$' },
|
|
29
|
+
name: { type: "string" },
|
|
30
|
+
group_id: { type: "string" },
|
|
31
|
+
cartocss_key: { type: "string" },
|
|
32
|
+
source_path: { type: "string" },
|
|
33
|
+
description: { type: ["string", "null"] },
|
|
34
|
+
card_table: { type: "string" },
|
|
35
|
+
card_columns: { type: "string" },
|
|
36
|
+
card_html: { type: "string" },
|
|
37
|
+
is_public: { type: "boolean" },
|
|
38
|
+
is_static: { type: "boolean" },
|
|
39
|
+
enabled: { type: "boolean" },
|
|
40
|
+
geom: geometrySchema,
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export const getCartocssSchema = {
|
|
45
|
+
params: {
|
|
46
|
+
type: 'object',
|
|
47
|
+
required: ['id'],
|
|
48
|
+
properties: {
|
|
49
|
+
id: { type: 'string', pattern: '^([\\d\\w._-]+)$' }
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
querystring: {
|
|
53
|
+
type: 'object',
|
|
54
|
+
additionalProperties: false,
|
|
55
|
+
properties: {
|
|
56
|
+
nocache: { type: 'number', enum: [1] },
|
|
57
|
+
sql: { type: 'number', enum: [1] },
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export const addCartocssSchema = {
|
|
63
|
+
params: {
|
|
64
|
+
type: 'object',
|
|
65
|
+
required: ['id'],
|
|
66
|
+
properties: {
|
|
67
|
+
id: { type: 'string', pattern: '^([\\d\\w._-]+)$' }
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
body: cssBodySchema,
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export default null;
|
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
import { pgClients, dataUpdate } from '@opengis/fastify-table/utils.js';
|
|
2
|
-
|
|
3
|
-
import uploadXML from '../../mapnik/functions/uploadXML.js';
|
|
4
|
-
import { NotFoundError } from '@opengis/fastify-table/errors.js';
|
|
5
|
-
|
|
6
|
-
export default async function addCartocss({ id, body, uid }, pg = pgClients.client) {
|
|
7
|
-
const cartocss = await pg.query('select cartocss_id, source_path, config, style from gis.cartocss where cartocss_id=$1', [id]).then(el => el.rows?.[0]);
|
|
8
|
-
|
|
9
|
-
if (!cartocss) {
|
|
10
|
-
throw NotFoundError('cartocss not found');
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const sourcePath = body.source_path || cartocss.source_path;
|
|
14
|
-
|
|
15
|
-
const config = body.config || cartocss.config;
|
|
16
|
-
const style = body.style || cartocss.style;
|
|
17
|
-
|
|
18
|
-
const data = { ...body, config };
|
|
19
|
-
|
|
20
|
-
await dataUpdate({
|
|
21
|
-
pg,
|
|
22
|
-
id,
|
|
23
|
-
table: 'gis.cartocss',
|
|
24
|
-
data,
|
|
25
|
-
uid,
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
// if not from static xml file
|
|
29
|
-
if (!data.source_path) {
|
|
30
|
-
await uploadXML({
|
|
31
|
-
id,
|
|
32
|
-
dataset: config,
|
|
33
|
-
style,
|
|
34
|
-
source_path: sourcePath,
|
|
35
|
-
}, pg);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return { message: 'cartocss updated', code: 200 };
|
|
39
|
-
}
|
|
1
|
+
import { pgClients, dataUpdate } from '@opengis/fastify-table/utils.js';
|
|
2
|
+
|
|
3
|
+
import uploadXML from '../../mapnik/functions/uploadXML.js';
|
|
4
|
+
import { NotFoundError } from '@opengis/fastify-table/errors.js';
|
|
5
|
+
|
|
6
|
+
export default async function addCartocss({ id, body, uid }, pg = pgClients.client) {
|
|
7
|
+
const cartocss = await pg.query('select cartocss_id, source_path, config, style from gis.cartocss where cartocss_id=$1', [id]).then(el => el.rows?.[0]);
|
|
8
|
+
|
|
9
|
+
if (!cartocss) {
|
|
10
|
+
throw NotFoundError('cartocss not found');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const sourcePath = body.source_path || cartocss.source_path;
|
|
14
|
+
|
|
15
|
+
const config = body.config || cartocss.config;
|
|
16
|
+
const style = body.style || cartocss.style;
|
|
17
|
+
|
|
18
|
+
const data = { ...body, config };
|
|
19
|
+
|
|
20
|
+
await dataUpdate({
|
|
21
|
+
pg,
|
|
22
|
+
id,
|
|
23
|
+
table: 'gis.cartocss',
|
|
24
|
+
data,
|
|
25
|
+
uid,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
// if not from static xml file
|
|
29
|
+
if (!data.source_path) {
|
|
30
|
+
await uploadXML({
|
|
31
|
+
id,
|
|
32
|
+
dataset: config,
|
|
33
|
+
style,
|
|
34
|
+
source_path: sourcePath,
|
|
35
|
+
}, pg);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return { message: 'cartocss updated', code: 200 };
|
|
39
|
+
}
|