@opengis/gis 0.2.207 → 0.2.208
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-Das_4-zP.js → CardIcon-iGo8QJu9.js} +1 -1
- package/dist/{EntityTablePage-VnczwXQf.js → EntityTablePage-BiVoVAhN.js} +2 -2
- package/dist/{ExtentOutlineLayer.vue_vue_type_script_setup_true_lang-CSmMFcSb.js → ExtentOutlineLayer.vue_vue_type_script_setup_true_lang-BdL5cQgN.js} +1 -1
- package/dist/{MapSettings-DQ8UiQm3.js → MapSettings-CXqiYxV4.js} +2 -2
- package/dist/{MapToolbarRight.vue_vue_type_script_setup_true_lang-D1pkL5Zi.js → MapToolbarRight.vue_vue_type_script_setup_true_lang-BHCChxmg.js} +1 -1
- package/dist/{RastersTablePage-P5UlG30e.js → RastersTablePage-Dgk1wp3d.js} +2 -2
- package/dist/{cartocss-jQ06BuDY.js → cartocss-BIpgQU6F.js} +6 -6
- package/dist/{import-utils-BSzqf3hF.js → import-utils-CfXKgZFd.js} +1 -1
- package/dist/{index-Bbe7SAdS.js → index-CM_DTEUa.js} +49 -43
- package/dist/index.css +1 -1
- package/dist/index.js +1 -1
- package/dist/index.umd.cjs +48 -42
- package/dist/{raster-C9rmMnma.js → raster-D_vEBha8.js} +3 -3
- package/dist/{register-j_ATka3H.js → register-C5_Un1Ms.js} +3 -3
- package/dist/service-JN82JN81.js +3676 -0
- package/dist/{vs-datatable-Zl_KZIHN.js → vs-datatable--K-DxayK.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 +79 -79
- 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 +248 -248
- 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 +76 -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/fonts/index.js +1933 -1933
- 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 +327 -327
- package/server/routes/map/functions/jsonData.js +206 -206
- package/server/routes/map/functions/layerList.js +144 -144
- 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 +246 -246
- 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 +191 -191
- package/server/routes/map/map.route.js +283 -283
- package/server/routes/map/map.route.test.js +693 -693
- 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 +328 -328
- package/server/routes/registers/functions/getFilterSQLParametrized/getFilterQuery.js +126 -126
- package/server/routes/registers/functions/getFilterSQLParametrized/getRangeQuery.js +353 -353
- package/server/routes/registers/functions/getFilterSQLParametrized/index.js +81 -81
- package/server/routes/registers/functions/getTableColumnMeta.js +148 -148
- 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 +310 -310
- package/server/routes/registers/functions/handleRegistryRequest.js +178 -178
- package/server/routes/registers/functions/map.registry.js +87 -87
- package/server/routes/registers/registers.route.js +92 -92
- package/server/routes/registers/registers.route.test.js +173 -173
- package/server/routes/registers/registers.schema.js +276 -276
- 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 +124 -124
- 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 +171 -171
- package/server/routes/services/services.schema.js +459 -459
- 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/dist/service-DJAlc1rE.js +0 -3484
|
@@ -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
|
+
}
|