@opengis/fastify-table 1.1.49 → 1.1.50
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/.gitlab-ci.yml +18 -0
- package/README.md +26 -26
- package/config.js +10 -10
- package/cron/controllers/cronApi.js +22 -22
- package/cron/controllers/utils/cronList.js +1 -1
- package/cron/index.js +10 -10
- package/crud/controllers/deleteCrud.js +9 -4
- package/crud/controllers/insert.js +8 -7
- package/crud/controllers/update.js +13 -10
- package/crud/controllers/utils/xssInjection.js +72 -72
- package/crud/funcs/getAccess.js +12 -24
- package/crud/funcs/getToken.js +27 -27
- package/crud/funcs/isFileExists.js +13 -13
- package/crud/funcs/setToken.js +53 -53
- package/package.json +7 -6
- package/redis/funcs/getRedis.js +23 -23
- package/server/migrations/log.sql +80 -80
- package/table/controllers/data.js +41 -25
- package/table/controllers/table.js +26 -22
- package/table/index.js +3 -50
- package/table/schema.js +54 -0
- package/test/config.example +18 -18
- package/test/funcs/pg.test.js +34 -34
- package/test/funcs/redis.test.js +19 -19
- package/test/templates/cls/test.json +9 -9
- package/test/templates/form/cp_building.form.json +32 -32
- package/test/templates/select/account_id.json +3 -3
- package/test/templates/select/storage.data.json +2 -2
- package/test/templates/table/gis.dataset.table.json +20 -20
- package/util/controllers/next.id.js +4 -4
- package/util/controllers/properties.get.js +19 -19
- package/util/index.js +23 -23
package/table/schema.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
const tableSchema = {
|
|
2
|
+
querystring1: {
|
|
3
|
+
page: { type: 'string', pattern: '^(\\d+)$' },
|
|
4
|
+
order: { type: 'string', pattern: '^(\\d+)$' },
|
|
5
|
+
filter: { type: 'string', pattern: '^([\\w\\d_-]+)=([\\w\\d_-]+)$' },
|
|
6
|
+
},
|
|
7
|
+
params: {
|
|
8
|
+
id: { type: 'string', pattern: '^([\\d\\w]+)$' },
|
|
9
|
+
table: { type: 'string', pattern: '^([\\w\\d_.]+)$' },
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const searchSchema = {
|
|
14
|
+
querystring: {
|
|
15
|
+
page: { type: 'string', pattern: '^(\\d+)$' },
|
|
16
|
+
limit: { type: 'string', pattern: '^(\\d+)$' },
|
|
17
|
+
order: { type: 'string', pattern: '^([\\w_.]+)$' },
|
|
18
|
+
desc: { type: 'string', pattern: '^(desc)|(asc)$' },
|
|
19
|
+
key: { type: 'string', pattern: '^([\\w\\d_]+)$' },
|
|
20
|
+
table: { type: 'string', pattern: '^([\\w\\d_.]+)$' },
|
|
21
|
+
sql: { type: 'string', pattern: '^(\\d)$' },
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const suggestSchema = {
|
|
26
|
+
querystring: {
|
|
27
|
+
lang: { type: 'string', pattern: '^([\\w.]+)$' },
|
|
28
|
+
// parent: { type: 'string', pattern: '^([\\w,./]+)$' },
|
|
29
|
+
sel: { type: 'string', pattern: '^([\\w,./]+)$' },
|
|
30
|
+
name: { type: 'string', pattern: '^([\\w,./]+)$' },
|
|
31
|
+
// key: { type: 'string', pattern: '^([\\w\\d_]+)$' },
|
|
32
|
+
// val: { type: 'string', pattern: '^([\\w.,]+)$' },
|
|
33
|
+
sql: { type: 'string', pattern: '^(\\d)$' },
|
|
34
|
+
},
|
|
35
|
+
params: {
|
|
36
|
+
id: { type: 'string', pattern: '^([\\d\\w]+)$' },
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const formSchema = {
|
|
41
|
+
params: {
|
|
42
|
+
form: { type: 'string', pattern: '^([\\w\\d_.]+)$' },
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const filterSchema = {
|
|
47
|
+
params: {
|
|
48
|
+
table: { type: 'string', pattern: '^([\\w\\d_.]+)$' },
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export {
|
|
53
|
+
tableSchema, searchSchema, suggestSchema, formSchema, filterSchema,
|
|
54
|
+
};
|
package/test/config.example
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import config from '../config.js';
|
|
2
|
-
|
|
3
|
-
Object.assign(config, {
|
|
4
|
-
folder: 'test/templates',
|
|
5
|
-
pg: {
|
|
6
|
-
host: '192.168.3.160',
|
|
7
|
-
port: 5434,
|
|
8
|
-
database: 'mbk_rivne_dma',
|
|
9
|
-
user: 'postgres',
|
|
10
|
-
password: 'postgres',
|
|
11
|
-
},
|
|
12
|
-
redis: {
|
|
13
|
-
host: '192.168.3.160',
|
|
14
|
-
port: 6379,
|
|
15
|
-
family: 4,
|
|
16
|
-
},
|
|
17
|
-
});
|
|
18
|
-
export default config;
|
|
1
|
+
import config from '../config.js';
|
|
2
|
+
|
|
3
|
+
Object.assign(config, {
|
|
4
|
+
folder: 'test/templates',
|
|
5
|
+
pg: {
|
|
6
|
+
host: '192.168.3.160',
|
|
7
|
+
port: 5434,
|
|
8
|
+
database: 'mbk_rivne_dma',
|
|
9
|
+
user: 'postgres',
|
|
10
|
+
password: 'postgres',
|
|
11
|
+
},
|
|
12
|
+
redis: {
|
|
13
|
+
host: '192.168.3.160',
|
|
14
|
+
port: 6379,
|
|
15
|
+
family: 4,
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
export default config;
|
package/test/funcs/pg.test.js
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import { test } from 'node:test';
|
|
2
|
-
import assert from 'node:assert';
|
|
3
|
-
|
|
4
|
-
import '../config.js';
|
|
5
|
-
|
|
6
|
-
import getMeta from '../../pg/funcs/getMeta.js';
|
|
7
|
-
import autoIndex from '../../pg/funcs/autoIndex.js';
|
|
8
|
-
import pgClients from '../../pg/pgClients.js';
|
|
9
|
-
import rclient from '../../redis/client.js';
|
|
10
|
-
// import pgClients from '../../pg/funcs/pgClients.js';
|
|
11
|
-
|
|
12
|
-
test('funcs pg', async (t) => {
|
|
13
|
-
await pgClients.client.init();
|
|
14
|
-
await t.test('getMeta', async () => {
|
|
15
|
-
const { columns } = await getMeta({ table: 'gis.dataset' });
|
|
16
|
-
// console.log(columns)
|
|
17
|
-
assert.ok(columns);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
/* await t.test('getPG', async (t) => {
|
|
21
|
-
const data = await getPG({});
|
|
22
|
-
assert.ok(data);
|
|
23
|
-
}); */
|
|
24
|
-
|
|
25
|
-
await t.test('autoIndex', async () => {
|
|
26
|
-
await autoIndex({ table: 'gis.dataset', columns: ['service_type'] });
|
|
27
|
-
assert.ok(1);
|
|
28
|
-
});
|
|
29
|
-
t.after(() => {
|
|
30
|
-
pgClients.client.end();
|
|
31
|
-
|
|
32
|
-
rclient.quit();
|
|
33
|
-
});
|
|
34
|
-
});
|
|
1
|
+
import { test } from 'node:test';
|
|
2
|
+
import assert from 'node:assert';
|
|
3
|
+
|
|
4
|
+
import '../config.js';
|
|
5
|
+
|
|
6
|
+
import getMeta from '../../pg/funcs/getMeta.js';
|
|
7
|
+
import autoIndex from '../../pg/funcs/autoIndex.js';
|
|
8
|
+
import pgClients from '../../pg/pgClients.js';
|
|
9
|
+
import rclient from '../../redis/client.js';
|
|
10
|
+
// import pgClients from '../../pg/funcs/pgClients.js';
|
|
11
|
+
|
|
12
|
+
test('funcs pg', async (t) => {
|
|
13
|
+
await pgClients.client.init();
|
|
14
|
+
await t.test('getMeta', async () => {
|
|
15
|
+
const { columns } = await getMeta({ table: 'gis.dataset' });
|
|
16
|
+
// console.log(columns)
|
|
17
|
+
assert.ok(columns);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
/* await t.test('getPG', async (t) => {
|
|
21
|
+
const data = await getPG({});
|
|
22
|
+
assert.ok(data);
|
|
23
|
+
}); */
|
|
24
|
+
|
|
25
|
+
await t.test('autoIndex', async () => {
|
|
26
|
+
await autoIndex({ table: 'gis.dataset', columns: ['service_type'] });
|
|
27
|
+
assert.ok(1);
|
|
28
|
+
});
|
|
29
|
+
t.after(() => {
|
|
30
|
+
pgClients.client.end();
|
|
31
|
+
|
|
32
|
+
rclient.quit();
|
|
33
|
+
});
|
|
34
|
+
});
|
package/test/funcs/redis.test.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { test } from 'node:test';
|
|
2
|
-
import assert from 'node:assert';
|
|
3
|
-
|
|
4
|
-
import '../config.js';
|
|
5
|
-
|
|
6
|
-
import rclient from '../../redis/client.js';
|
|
7
|
-
|
|
8
|
-
test('funcs redis', async (t) => {
|
|
9
|
-
await t.test('get/set', async () => {
|
|
10
|
-
await rclient.set('test', '1');
|
|
11
|
-
const d = await rclient.get('test');
|
|
12
|
-
// console.log(columns)
|
|
13
|
-
assert.equal(d, '1');
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
t.after(() => {
|
|
17
|
-
rclient.quit();
|
|
18
|
-
});
|
|
19
|
-
});
|
|
1
|
+
import { test } from 'node:test';
|
|
2
|
+
import assert from 'node:assert';
|
|
3
|
+
|
|
4
|
+
import '../config.js';
|
|
5
|
+
|
|
6
|
+
import rclient from '../../redis/client.js';
|
|
7
|
+
|
|
8
|
+
test('funcs redis', async (t) => {
|
|
9
|
+
await t.test('get/set', async () => {
|
|
10
|
+
await rclient.set('test', '1');
|
|
11
|
+
const d = await rclient.get('test');
|
|
12
|
+
// console.log(columns)
|
|
13
|
+
assert.equal(d, '1');
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
t.after(() => {
|
|
17
|
+
rclient.quit();
|
|
18
|
+
});
|
|
19
|
+
});
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
[
|
|
2
|
-
{
|
|
3
|
-
"id": 1,
|
|
4
|
-
"text": "test"
|
|
5
|
-
},
|
|
6
|
-
{
|
|
7
|
-
"id": 2,
|
|
8
|
-
"text": "test2"
|
|
9
|
-
}
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": 1,
|
|
4
|
+
"text": "test"
|
|
5
|
+
},
|
|
6
|
+
{
|
|
7
|
+
"id": 2,
|
|
8
|
+
"text": "test2"
|
|
9
|
+
}
|
|
10
10
|
]
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
{
|
|
2
|
-
"schema": {
|
|
3
|
-
|
|
4
|
-
"cp_umuni_id": {
|
|
5
|
-
"type": "Text",
|
|
6
|
-
"ua": "ID UMUNI"
|
|
7
|
-
},
|
|
8
|
-
"cp_year": {
|
|
9
|
-
"type": "Text",
|
|
10
|
-
"ua": "Рік будівництва"
|
|
11
|
-
},
|
|
12
|
-
"cp_date_en_audit": {
|
|
13
|
-
"type": "DatePicker",
|
|
14
|
-
"ua": "Дата проведення останнього енергоаудиту"
|
|
15
|
-
},
|
|
16
|
-
"cp_certificate": {
|
|
17
|
-
"type": "Text",
|
|
18
|
-
"ua": "Сертифікат енергоефективності будівлі",
|
|
19
|
-
"help": "Вкажіть посилання"
|
|
20
|
-
},
|
|
21
|
-
"cp_pkd": {
|
|
22
|
-
"type": "Autocomplete",
|
|
23
|
-
"data": "customer_name",
|
|
24
|
-
"add": {
|
|
25
|
-
"model": "crm_acc.crm_account",
|
|
26
|
-
"ua": "Додати",
|
|
27
|
-
"form": "account_light.form"
|
|
28
|
-
},
|
|
29
|
-
"ua": "Замовник ПКД"
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
"label_style": "vertical"
|
|
1
|
+
{
|
|
2
|
+
"schema": {
|
|
3
|
+
|
|
4
|
+
"cp_umuni_id": {
|
|
5
|
+
"type": "Text",
|
|
6
|
+
"ua": "ID UMUNI"
|
|
7
|
+
},
|
|
8
|
+
"cp_year": {
|
|
9
|
+
"type": "Text",
|
|
10
|
+
"ua": "Рік будівництва"
|
|
11
|
+
},
|
|
12
|
+
"cp_date_en_audit": {
|
|
13
|
+
"type": "DatePicker",
|
|
14
|
+
"ua": "Дата проведення останнього енергоаудиту"
|
|
15
|
+
},
|
|
16
|
+
"cp_certificate": {
|
|
17
|
+
"type": "Text",
|
|
18
|
+
"ua": "Сертифікат енергоефективності будівлі",
|
|
19
|
+
"help": "Вкажіть посилання"
|
|
20
|
+
},
|
|
21
|
+
"cp_pkd": {
|
|
22
|
+
"type": "Autocomplete",
|
|
23
|
+
"data": "customer_name",
|
|
24
|
+
"add": {
|
|
25
|
+
"model": "crm_acc.crm_account",
|
|
26
|
+
"ua": "Додати",
|
|
27
|
+
"form": "account_light.form"
|
|
28
|
+
},
|
|
29
|
+
"ua": "Замовник ПКД"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"label_style": "vertical"
|
|
33
33
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
{
|
|
2
|
-
"db": "mbk_lviv_dma",
|
|
3
|
-
"searchColumn": "alternative_name"
|
|
1
|
+
{
|
|
2
|
+
"db": "mbk_lviv_dma",
|
|
3
|
+
"searchColumn": "alternative_name"
|
|
4
4
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
{
|
|
2
|
-
"key": "dataset_id"
|
|
1
|
+
{
|
|
2
|
+
"key": "dataset_id"
|
|
3
3
|
}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
{
|
|
2
|
-
"columns": [
|
|
3
|
-
{
|
|
4
|
-
"name": "dataset_id",
|
|
5
|
-
"title": "22"
|
|
6
|
-
},
|
|
7
|
-
{
|
|
8
|
-
"name": "dataset_name",
|
|
9
|
-
"title": "dataset_name"
|
|
10
|
-
}
|
|
11
|
-
],
|
|
12
|
-
"table": "gis.dataset",
|
|
13
|
-
"order": "dataset_name",
|
|
14
|
-
"filters": [
|
|
15
|
-
{
|
|
16
|
-
"ua": "Назва набору",
|
|
17
|
-
"name": "dataset_name",
|
|
18
|
-
"type": "text"
|
|
19
|
-
}
|
|
20
|
-
]
|
|
1
|
+
{
|
|
2
|
+
"columns": [
|
|
3
|
+
{
|
|
4
|
+
"name": "dataset_id",
|
|
5
|
+
"title": "22"
|
|
6
|
+
},
|
|
7
|
+
{
|
|
8
|
+
"name": "dataset_name",
|
|
9
|
+
"title": "dataset_name"
|
|
10
|
+
}
|
|
11
|
+
],
|
|
12
|
+
"table": "gis.dataset",
|
|
13
|
+
"order": "dataset_name",
|
|
14
|
+
"filters": [
|
|
15
|
+
{
|
|
16
|
+
"ua": "Назва набору",
|
|
17
|
+
"name": "dataset_name",
|
|
18
|
+
"type": "text"
|
|
19
|
+
}
|
|
20
|
+
]
|
|
21
21
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export default async function nextId({ pg }) {
|
|
2
|
-
const { id } = await pg.one('select next_id() as id');
|
|
3
|
-
return { id: id.toString() };
|
|
4
|
-
};
|
|
1
|
+
export default async function nextId({ pg }) {
|
|
2
|
+
const { id } = await pg.one('select next_id() as id');
|
|
3
|
+
return { id: id.toString() };
|
|
4
|
+
};
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
export default async function getExtraProperties({
|
|
2
|
-
pg, params = {},
|
|
3
|
-
}) {
|
|
4
|
-
const { id } = params;
|
|
5
|
-
if (!id) {
|
|
6
|
-
return { message: 'not enougn params', status: 400 };
|
|
7
|
-
}
|
|
8
|
-
try {
|
|
9
|
-
const { rows = [] } = pg.pk?.['crm.properties']
|
|
10
|
-
? await pg.query(`select property_key, property_type, property_text, property_int,
|
|
11
|
-
property_json, property_date from crm.properties where property_key is not null and object_id=$1`, [id])
|
|
12
|
-
: {};
|
|
13
|
-
if (!rows.length) return {};
|
|
14
|
-
|
|
15
|
-
const data = rows.reduce((acc, curr) => Object.assign(acc, { [curr.property_key]: curr[`property_${curr.property_type}`] }), {});
|
|
16
|
-
return { message: data, status: 200 };
|
|
17
|
-
} catch (err) {
|
|
18
|
-
return { error: err.toString(), status: 500 };
|
|
19
|
-
}
|
|
1
|
+
export default async function getExtraProperties({
|
|
2
|
+
pg, params = {},
|
|
3
|
+
}) {
|
|
4
|
+
const { id } = params;
|
|
5
|
+
if (!id) {
|
|
6
|
+
return { message: 'not enougn params', status: 400 };
|
|
7
|
+
}
|
|
8
|
+
try {
|
|
9
|
+
const { rows = [] } = pg.pk?.['crm.properties']
|
|
10
|
+
? await pg.query(`select property_key, property_type, property_text, property_int,
|
|
11
|
+
property_json, property_date from crm.properties where property_key is not null and object_id=$1`, [id])
|
|
12
|
+
: {};
|
|
13
|
+
if (!rows.length) return {};
|
|
14
|
+
|
|
15
|
+
const data = rows.reduce((acc, curr) => Object.assign(acc, { [curr.property_key]: curr[`property_${curr.property_type}`] }), {});
|
|
16
|
+
return { message: data, status: 200 };
|
|
17
|
+
} catch (err) {
|
|
18
|
+
return { error: err.toString(), status: 500 };
|
|
19
|
+
}
|
|
20
20
|
}
|
package/util/index.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import getExtraProperties from './controllers/properties.get.js';
|
|
2
|
-
import addExtraProperties from './controllers/properties.add.js';
|
|
3
|
-
import nextId from './controllers/next.id.js';
|
|
4
|
-
import statusMonitor from './controllers/status.monitor.js';
|
|
5
|
-
import loggerFile from './controllers/logger.file.js';
|
|
6
|
-
|
|
7
|
-
const propertiesSchema = {
|
|
8
|
-
params: {
|
|
9
|
-
id: { type: 'string', pattern: '^([\\d\\w]+)$' },
|
|
10
|
-
},
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
async function plugin(fastify, config = {}) {
|
|
14
|
-
const prefix = config.prefix || '/api';
|
|
15
|
-
|
|
16
|
-
fastify.get(`${prefix}/next-id`, {}, nextId);
|
|
17
|
-
fastify.get(`${prefix}/status-monitor`, {}, statusMonitor);
|
|
18
|
-
fastify.get(`${prefix}/properties/:id`, { schema: propertiesSchema }, getExtraProperties);
|
|
19
|
-
fastify.post(`${prefix}/properties/:id`, { schema: propertiesSchema }, addExtraProperties);
|
|
20
|
-
fastify.get('/logger-file/*', { config: { policy: ['log'] } }, loggerFile);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export default plugin;
|
|
1
|
+
import getExtraProperties from './controllers/properties.get.js';
|
|
2
|
+
import addExtraProperties from './controllers/properties.add.js';
|
|
3
|
+
import nextId from './controllers/next.id.js';
|
|
4
|
+
import statusMonitor from './controllers/status.monitor.js';
|
|
5
|
+
import loggerFile from './controllers/logger.file.js';
|
|
6
|
+
|
|
7
|
+
const propertiesSchema = {
|
|
8
|
+
params: {
|
|
9
|
+
id: { type: 'string', pattern: '^([\\d\\w]+)$' },
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
async function plugin(fastify, config = {}) {
|
|
14
|
+
const prefix = config.prefix || '/api';
|
|
15
|
+
|
|
16
|
+
fastify.get(`${prefix}/next-id`, {}, nextId);
|
|
17
|
+
fastify.get(`${prefix}/status-monitor`, {}, statusMonitor);
|
|
18
|
+
fastify.get(`${prefix}/properties/:id`, { schema: propertiesSchema }, getExtraProperties);
|
|
19
|
+
fastify.post(`${prefix}/properties/:id`, { schema: propertiesSchema }, addExtraProperties);
|
|
20
|
+
fastify.get('/logger-file/*', { config: { policy: ['log'] } }, loggerFile);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default plugin;
|