@opengis/fastify-table 1.3.75 → 1.4.0
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/index.js +12 -15
- package/package.json +5 -7
- package/server/routes/cron/index.js +5 -2
- package/server/routes/crud/index.js +6 -3
- package/server/routes/data/controllers/tableData.js +4 -5
- package/server/routes/data/schema.js +52 -36
- package/server/routes/logger/index.js +7 -4
- package/server/routes/menu/controllers/getMenu.js +1 -1
- package/server/routes/properties/index.js +5 -2
- package/server/routes/table/controllers/data.js +3 -1
- package/server/routes/table/schema.js +57 -42
- package/server/routes/templates/schema.js +6 -3
package/index.js
CHANGED
|
@@ -51,23 +51,20 @@ async function plugin(fastify, opt) {
|
|
|
51
51
|
config.root = opt.root;
|
|
52
52
|
config.mapServerRoot = opt.mapServerRoot;
|
|
53
53
|
|
|
54
|
-
//
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
// fastify.register(import('@fastify/sensible'), {
|
|
55
|
+
// errorHandler: false,
|
|
56
|
+
// });
|
|
57
|
+
|
|
58
|
+
// fastify.register(import('@fastify/url-data'), {
|
|
59
|
+
// errorHandler: false,
|
|
60
|
+
// });
|
|
61
|
+
|
|
62
|
+
if (config.disableCors) {
|
|
63
|
+
fastify.addHook('onSend', async (request, reply) => {
|
|
64
|
+
reply.header('Access-Control-Allow-Origin', '*');
|
|
65
|
+
});
|
|
57
66
|
}
|
|
58
67
|
|
|
59
|
-
fastify.register(import('@fastify/sensible'), {
|
|
60
|
-
errorHandler: false,
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
fastify.register(import('@fastify/url-data'), {
|
|
64
|
-
errorHandler: false,
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
fastify.addHook('onSend', async (request, reply) => {
|
|
68
|
-
if (config.disableCors) reply.header('Access-Control-Allow-Origin', '*');
|
|
69
|
-
});
|
|
70
|
-
|
|
71
68
|
fastify.addHook('onReady', async () => {
|
|
72
69
|
if (existsSync('locales')) {
|
|
73
70
|
const subdirs = (readdirSync('locales', { withFileTypes: true })).filter(el => el.isDirectory());
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opengis/fastify-table",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "core-plugins",
|
|
6
6
|
"keywords": [
|
|
@@ -28,11 +28,9 @@
|
|
|
28
28
|
"compress": "node compress.js"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@fastify/http-proxy": "
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"fastify": "4.26.1",
|
|
35
|
-
"fastify-plugin": "4.0.0",
|
|
31
|
+
"@fastify/http-proxy": "11.1.2",
|
|
32
|
+
"fastify": "5.3.3",
|
|
33
|
+
"fastify-plugin": "5.0.1",
|
|
36
34
|
"handlebars": "4.7.8",
|
|
37
35
|
"ioredis": "5.3.2",
|
|
38
36
|
"js-yaml": "4.1.0",
|
|
@@ -50,4 +48,4 @@
|
|
|
50
48
|
},
|
|
51
49
|
"author": "Softpro",
|
|
52
50
|
"license": "ISC"
|
|
53
|
-
}
|
|
51
|
+
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import cronApi from './controllers/cronApi.js';
|
|
2
2
|
|
|
3
3
|
const cronSchema = {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
type: 'object',
|
|
5
|
+
properties: {
|
|
6
|
+
params: {
|
|
7
|
+
name: { type: 'string', pattern: '^([\\d\\w._-]+)$' },
|
|
8
|
+
},
|
|
6
9
|
},
|
|
7
10
|
};
|
|
8
11
|
|
|
@@ -4,9 +4,12 @@ import deleteCrud from './controllers/deleteCrud.js';
|
|
|
4
4
|
import table from './controllers/table.js';
|
|
5
5
|
|
|
6
6
|
const tableSchema = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
type: 'object',
|
|
8
|
+
properties: {
|
|
9
|
+
params: {
|
|
10
|
+
id: { type: 'string', pattern: '^([\\w\\d_.]+)$' },
|
|
11
|
+
table: { type: 'string', pattern: '^([\\w\\d_.]+)$' },
|
|
12
|
+
},
|
|
10
13
|
},
|
|
11
14
|
};
|
|
12
15
|
|
|
@@ -2,10 +2,11 @@ import {
|
|
|
2
2
|
getOpt, getMeta, getTemplate, getData, pgClients,
|
|
3
3
|
} from '../../../../utils.js';
|
|
4
4
|
|
|
5
|
-
export default async function getTableData(req) {
|
|
5
|
+
export default async function getTableData(req, reply) {
|
|
6
6
|
const {
|
|
7
7
|
user = {}, params = {}, query = {}, pg = pgClients.client,
|
|
8
8
|
} = req;
|
|
9
|
+
|
|
9
10
|
const {
|
|
10
11
|
filter, limit, page, search, sql, state, order,
|
|
11
12
|
} = query || {};
|
|
@@ -18,8 +19,6 @@ export default async function getTableData(req) {
|
|
|
18
19
|
const loadTable = await getTemplate('table', tokenData.table);
|
|
19
20
|
|
|
20
21
|
if (!loadTable) {
|
|
21
|
-
// const resp = await getData({ id, table: params.table, pg, filter, state, limit, page, search, order, user, sql, contextQuery: tokenData.query, sufix: false });
|
|
22
|
-
// return resp;
|
|
23
22
|
const { rows = [], fields = [] } = await pg.query(`select ${tokenData.columns || '*'} from ${tokenData.table} where ${tokenData.query || 'true'} limit 10`);
|
|
24
23
|
const meta = await getMeta({ pg, table: tokenData.table });
|
|
25
24
|
const columns = (meta?.columns || fields).map(el => ({ name: el.name, type: pg.pgType?.[el.dataTypeID], title: el.title }));
|
|
@@ -28,7 +27,7 @@ export default async function getTableData(req) {
|
|
|
28
27
|
|
|
29
28
|
const resp = await getData({
|
|
30
29
|
id, table: tokenData.table, pg, filter, state, limit, page, search, order, user, sql, contextQuery: tokenData.query,
|
|
31
|
-
});
|
|
30
|
+
}, reply);
|
|
32
31
|
return resp;
|
|
33
32
|
}
|
|
34
33
|
|
|
@@ -49,7 +48,7 @@ export default async function getTableData(req) {
|
|
|
49
48
|
|
|
50
49
|
const res = await getData({
|
|
51
50
|
id, table: params.table, pg, filter, state, limit, page, search, order, user, sql, contextQuery,
|
|
52
|
-
});
|
|
51
|
+
}, reply);
|
|
53
52
|
|
|
54
53
|
return res;
|
|
55
54
|
}
|
|
@@ -1,54 +1,70 @@
|
|
|
1
1
|
const tableDataSchema = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
2
|
+
type: 'object',
|
|
3
|
+
properties: {
|
|
4
|
+
querystring: {
|
|
5
|
+
limit: { type: 'string', pattern: '^(\\d+)$' },
|
|
6
|
+
page: { type: 'string', pattern: '^(\\d+)$' },
|
|
7
|
+
// filter: { type: 'string', pattern: '^([\\w\\d_-]+)=([А-Яа-яҐґЄєІіЇї\\d\\w\\s\\/\\[\\]\\(\\)\\{\\}\\|,.!?;:—_=-@%#$&^*+=`~]+)$' },
|
|
8
|
+
// search: { type: 'string', pattern: '^([А-Яа-яҐґЄєІіЇї\\d\\w\\s\\/\\[\\]\\(\\)\\{\\}\\|,.!?;:—_=-@%#$&^*+=`~]+)$' },
|
|
9
|
+
order: { type: 'string', pattern: '^([\\d\\w_.-]+)$' },
|
|
10
|
+
desc: { type: 'string', pattern: '^(\\d+)$' },
|
|
11
|
+
state: { type: 'string', pattern: '^([\\d\\w._-]+)$' },
|
|
12
|
+
custom: { type: 'string', pattern: '^([\\d\\w._-]+)$' },
|
|
13
|
+
bbox: { type: 'string', pattern: '^([\\d\\s,.-]+)$' },
|
|
14
|
+
polyline: { type: 'string', pattern: '^([\\d\\w|@{}~_`]+)$' },
|
|
15
|
+
// key: { type: 'string', pattern: '^([\\d\\w_]+)$' },
|
|
16
|
+
sql: { type: 'string', pattern: '^(\\d)$' },
|
|
17
|
+
},
|
|
18
|
+
params: {
|
|
19
|
+
id: { type: 'string', pattern: '^([\\d\\w_.-]+)$' },
|
|
20
|
+
table: { type: 'string', pattern: '^([\\d\\w_.-]+)$' },
|
|
21
|
+
},
|
|
15
22
|
},
|
|
16
|
-
params: {
|
|
17
|
-
id: { type: 'string', pattern: '^([\\d\\w_.-]+)$' },
|
|
18
|
-
table: { type: 'string', pattern: '^([\\d\\w_.-]+)$' },
|
|
19
|
-
}
|
|
20
23
|
};
|
|
21
24
|
|
|
22
25
|
const tableDataIdSchema = {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
type: 'object',
|
|
27
|
+
properties: {
|
|
28
|
+
params: {
|
|
29
|
+
id: { type: 'string', pattern: '^([\\d\\w_.-]+)$' },
|
|
30
|
+
name: { type: 'string', pattern: '^([\\d\\w._-]+)$' },
|
|
31
|
+
},
|
|
32
|
+
},
|
|
27
33
|
};
|
|
28
34
|
|
|
29
35
|
const tableFilterSchema = {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
36
|
+
type: 'object',
|
|
37
|
+
properties: {
|
|
38
|
+
params: {
|
|
39
|
+
name: { type: 'string', pattern: '^([\\d\\w._-]+)$' },
|
|
40
|
+
},
|
|
41
|
+
},
|
|
33
42
|
};
|
|
34
43
|
|
|
35
44
|
const cardDataSchema = {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
45
|
+
type: 'object',
|
|
46
|
+
properties: {
|
|
47
|
+
params: {
|
|
48
|
+
id: { type: 'string', pattern: '^([\\d\\w_.-]+)$' },
|
|
49
|
+
table: { type: 'string', pattern: '^([\\d\\w._-]+)$' },
|
|
50
|
+
},
|
|
51
|
+
},
|
|
40
52
|
};
|
|
41
53
|
|
|
42
54
|
const cardTabDataSchema = {
|
|
43
|
-
|
|
44
|
-
|
|
55
|
+
type: 'object',
|
|
56
|
+
properties: {
|
|
57
|
+
querystring: {
|
|
58
|
+
sql: { type: 'string', pattern: '^(\\d)$' }
|
|
59
|
+
},
|
|
60
|
+
params: {
|
|
61
|
+
token: { type: 'string', pattern: '^([\\d\\w]+)$' },
|
|
62
|
+
},
|
|
45
63
|
},
|
|
46
|
-
params: {
|
|
47
|
-
token: { type: 'string', pattern: '^([\\d\\w]+)$' },
|
|
48
|
-
}
|
|
49
64
|
};
|
|
50
|
-
export {
|
|
65
|
+
export {
|
|
51
66
|
tableDataSchema, tableDataIdSchema, tableFilterSchema,
|
|
52
|
-
cardDataSchema, cardTabDataSchema
|
|
53
|
-
|
|
67
|
+
cardDataSchema, cardTabDataSchema,
|
|
68
|
+
};
|
|
69
|
+
|
|
54
70
|
export default null;
|
|
@@ -3,10 +3,13 @@ import loggerFile from './controllers/logger.file.js';
|
|
|
3
3
|
// import loggerTest from './controllers/logger.test.api.js';
|
|
4
4
|
|
|
5
5
|
const loggerSchema = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
type: 'object',
|
|
7
|
+
properties: {
|
|
8
|
+
querystring: {
|
|
9
|
+
download: { type: 'string', pattern: '^(\\d+)$' },
|
|
10
|
+
full: { type: 'string', pattern: '^(\\d+)$' },
|
|
11
|
+
dir: { type: 'string', pattern: '^(\\d+)$' },
|
|
12
|
+
},
|
|
10
13
|
},
|
|
11
14
|
};
|
|
12
15
|
|
|
@@ -2,8 +2,11 @@ import getExtraProperties from './controllers/properties.get.js';
|
|
|
2
2
|
import addExtraProperties from './controllers/properties.add.js';
|
|
3
3
|
|
|
4
4
|
const propertiesSchema = {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
type: 'object',
|
|
6
|
+
properties: {
|
|
7
|
+
params: {
|
|
8
|
+
id: { type: 'string', pattern: '^([\\d\\w]+)$' },
|
|
9
|
+
},
|
|
7
10
|
},
|
|
8
11
|
};
|
|
9
12
|
|
|
@@ -15,6 +15,8 @@ const components = {
|
|
|
15
15
|
|
|
16
16
|
const checkInline = {};
|
|
17
17
|
const maxLimit = 100;
|
|
18
|
+
const defaultLimit = 20;
|
|
19
|
+
|
|
18
20
|
export default async function dataAPI(req, reply, called) {
|
|
19
21
|
const {
|
|
20
22
|
pg = pgClients.client, params, query = {}, user = {}, contextQuery, sufix = true,
|
|
@@ -143,7 +145,7 @@ export default async function dataAPI(req, reply, called) {
|
|
|
143
145
|
|
|
144
146
|
const keyQuery = query.key && (loadTable?.key || tokenData?.key) && !objectId ? `${loadTable?.key || tokenData?.key}=$1` : null;
|
|
145
147
|
|
|
146
|
-
const limit = called ? (query.limit ||
|
|
148
|
+
const limit = (called ? (query.limit || defaultLimit) : Math.min(maxLimit, +(query.limit || defaultLimit))) || defaultLimit;
|
|
147
149
|
|
|
148
150
|
const offset = query.page && query.page > 0 && !objectId ? ` offset ${(query.page - 1) * limit}` : '';
|
|
149
151
|
// id, query, filter
|
|
@@ -1,62 +1,77 @@
|
|
|
1
1
|
const tableSchema = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
2
|
+
type: 'object',
|
|
3
|
+
properties: {
|
|
4
|
+
querystring: {
|
|
5
|
+
limit: { type: 'string', pattern: '^(\\d+)$' },
|
|
6
|
+
page: { type: 'string', pattern: '^(\\d+)$' },
|
|
7
|
+
// filter: { type: 'string', pattern: '^([\\w\\d_-]+)=([А-Яа-яҐґЄєІіЇї\\d\\w\\s\\/\\[\\]\\(\\)\\{\\}\\|,.!?;:—_=-@%#$&^*+=`~]+)$' },
|
|
8
|
+
// search: { type: 'string', pattern: '^([А-Яа-яҐґЄєІіЇї\\d\\w\\s\\/\\[\\]\\(\\)\\{\\}\\|,.!?;:—_=-@%#$&^*+=`~]+)$' },
|
|
9
|
+
order: { type: 'string', pattern: '^([\\d\\w_.-]+)$' },
|
|
10
|
+
desc: { type: 'string', pattern: '^(\\d+)$' },
|
|
11
|
+
// state: { type: 'string', pattern: '^([\\d\\w._-]+)$' },
|
|
12
|
+
// custom: { type: 'string', pattern: '^([\\d\\w._-]+)$' },
|
|
13
|
+
bbox: { type: 'string', pattern: '^([\\d\\s,.-]+)$' },
|
|
14
|
+
// polyline: { type: 'string', pattern: '^([\\d\\w\\|@\\/\\{\\}~_`]+)$' },
|
|
15
|
+
key: { type: 'string', pattern: '^([А-Яа-яҐґЄєІіЇї\\d\\w\\s_.-]+)$' },
|
|
16
|
+
uid: { type: 'string', pattern: '^([\\d\\w_.-]+)$' },
|
|
17
|
+
sql: { type: 'string', pattern: '^(\\d)$' },
|
|
18
|
+
},
|
|
19
|
+
params: {
|
|
20
|
+
id: { type: 'string', pattern: '^([\\d\\w]+)$' },
|
|
21
|
+
table: { type: 'string', pattern: '^([\\d\\w_.-]+)$' },
|
|
22
|
+
},
|
|
20
23
|
},
|
|
21
24
|
};
|
|
22
25
|
|
|
23
26
|
const searchSchema = {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
type: 'object',
|
|
28
|
+
properties: {
|
|
29
|
+
querystring: {
|
|
30
|
+
page: { type: 'string', pattern: '^(\\d+)$' },
|
|
31
|
+
limit: { type: 'string', pattern: '^(\\d+)$' },
|
|
32
|
+
order: { type: 'string', pattern: '^([\\d\\w_.-]+)$' },
|
|
33
|
+
desc: { type: 'string', pattern: '^(\\d+)$' },
|
|
34
|
+
key: { type: 'string', pattern: '^([А-Яа-яҐґЄєІіЇї\\d\\w\\s_.-]+)$' },
|
|
35
|
+
table: { type: 'string', pattern: '^([\\d\\w_.-]+)$' },
|
|
36
|
+
sql: { type: 'string', pattern: '^(\\d)$' },
|
|
37
|
+
},
|
|
32
38
|
},
|
|
33
39
|
};
|
|
34
40
|
|
|
35
41
|
const suggestSchema = {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
42
|
+
type: 'object',
|
|
43
|
+
properties: {
|
|
44
|
+
querystring: {
|
|
45
|
+
lang: { type: 'string', pattern: '^([\\w]+)$' },
|
|
46
|
+
parent: { type: 'string', pattern: '^([\\d\\w_.-]+)$' },
|
|
47
|
+
sel: { type: 'string', pattern: '^([\\d\\w_.-]+)$' },
|
|
48
|
+
name: { type: 'string', pattern: '^([\\d\\w_.-]+)$' },
|
|
49
|
+
// key: { type: 'string', pattern: '^([\\d\\w_.-]+)$' },
|
|
50
|
+
val: { type: 'string', pattern: '([\\d\\w]+)$' },
|
|
51
|
+
sql: { type: 'string', pattern: '^(\\d)$' },
|
|
52
|
+
count: { type: 'string', pattern: '^(\\d)$' },
|
|
53
|
+
},
|
|
54
|
+
params: {
|
|
55
|
+
// data: { type: 'string', pattern: '^([\\d\\w]+)$' },
|
|
56
|
+
},
|
|
48
57
|
},
|
|
49
58
|
};
|
|
50
59
|
|
|
51
60
|
const formSchema = {
|
|
52
|
-
|
|
53
|
-
|
|
61
|
+
type: 'object',
|
|
62
|
+
properties: {
|
|
63
|
+
params: {
|
|
64
|
+
form: { type: 'string', pattern: '^([\\d\\w_.-]+)$' },
|
|
65
|
+
},
|
|
54
66
|
},
|
|
55
67
|
};
|
|
56
68
|
|
|
57
69
|
const filterSchema = {
|
|
58
|
-
|
|
59
|
-
|
|
70
|
+
type: 'object',
|
|
71
|
+
properties: {
|
|
72
|
+
params: {
|
|
73
|
+
table: { type: 'string', pattern: '^([\\d\\w_.-]+)$' },
|
|
74
|
+
},
|
|
60
75
|
},
|
|
61
76
|
};
|
|
62
77
|
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
const getTemplateSchema = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
type: 'object',
|
|
3
|
+
properties: {
|
|
4
|
+
params: {
|
|
5
|
+
name: { type: 'string', pattern: '^([\\d\\w._-]+)$' },
|
|
6
|
+
// type: { type: 'string' },
|
|
7
|
+
},
|
|
5
8
|
},
|
|
6
9
|
};
|
|
7
10
|
|