@opengis/fastify-table 1.4.69 → 1.4.71
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/package.json +61 -61
- package/server/helpers/core/token.js +18 -18
- package/server/plugins/cron/funcs/addCron.js +52 -52
- package/server/plugins/crud/funcs/getOpt.js +14 -14
- package/server/plugins/crud/funcs/utils/getFolder.js +11 -11
- package/server/plugins/logger/errorStatus.js +19 -19
- package/server/plugins/migration/exec.migrations.js +1 -1
- package/server/plugins/pg/funcs/autoIndex.js +5 -5
- package/server/plugins/redis/client.js +8 -8
- package/server/plugins/redis/funcs/redisClients.js +3 -3
- package/server/plugins/table/funcs/getFilterSQL/util/getCustomQuery.js +13 -13
- package/server/plugins/table/funcs/getFilterSQL/util/getTableSql.js +34 -34
- package/server/plugins/table/funcs/getTemplates.js +19 -19
- package/server/plugins/table/funcs/gisIRColumn.js +82 -82
- package/server/plugins/table/funcs/loadTemplate.js +1 -1
- package/server/plugins/table/funcs/loadTemplatePath.js +1 -1
- package/server/plugins/table/funcs/userTemplateDir.js +1 -1
- package/server/routes/table/controllers/getFormByTable.js +14 -10
- package/server/routes/table/controllers/search.js +74 -74
- package/server/routes/table/controllers/tableData.js +3 -1
- package/server/routes/table/functions/getData.js +3 -2
- package/server/routes/widget/controllers/widget.del.js +89 -89
- package/server/routes/widget/hook/onWidgetSet.js +13 -13
- package/server/routes/widget/index.mjs +38 -38
package/package.json
CHANGED
|
@@ -1,62 +1,62 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@opengis/fastify-table",
|
|
3
|
-
"version": "1.4.
|
|
4
|
-
"type": "module",
|
|
5
|
-
"description": "core-plugins",
|
|
6
|
-
"keywords": [
|
|
7
|
-
"fastify",
|
|
8
|
-
"table",
|
|
9
|
-
"crud",
|
|
10
|
-
"pg",
|
|
11
|
-
"backend"
|
|
12
|
-
],
|
|
13
|
-
"main": "index.js",
|
|
14
|
-
"files": [
|
|
15
|
-
"server/*",
|
|
16
|
-
"index.js",
|
|
17
|
-
"utils.js",
|
|
18
|
-
"config.js",
|
|
19
|
-
"dblist.js",
|
|
20
|
-
"redactionList.js"
|
|
21
|
-
],
|
|
22
|
-
"scripts": {
|
|
23
|
-
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
|
|
24
|
-
"test": "node --test",
|
|
25
|
-
"test:helpers": "node --test .\\test\\helpers",
|
|
26
|
-
"test:routes": "node --test .\\test\\routes",
|
|
27
|
-
"test:functions": "node --test .\\test\\functions",
|
|
28
|
-
"compress": "node compress.js",
|
|
29
|
-
"dev1": "set NODE_ENV=dev&& node server.js",
|
|
30
|
-
"dev": "node --env-file=.env.dev --env-file=.env server",
|
|
31
|
-
"start": "node --env-file=.env server"
|
|
32
|
-
},
|
|
33
|
-
"dependencies": {
|
|
34
|
-
"@aws-sdk/client-s3": "3.554.0",
|
|
35
|
-
"@fastify/http-proxy": "11.1.2",
|
|
36
|
-
"@fastify/multipart": "9.0.3",
|
|
37
|
-
"@fastify/rate-limit": "10.3.0",
|
|
38
|
-
"@grpc/grpc-js": "1.10.6",
|
|
39
|
-
"@grpc/proto-loader": "0.7.12",
|
|
40
|
-
"better-sqlite3": "12.2.0",
|
|
41
|
-
"dotenv": "16.5.0",
|
|
42
|
-
"fastify": "5.3.3",
|
|
43
|
-
"fastify-plugin": "5.0.1",
|
|
44
|
-
"handlebars": "4.7.8",
|
|
45
|
-
"image-size": "1.2.0",
|
|
46
|
-
"ioredis": "5.3.2",
|
|
47
|
-
"js-yaml": "4.1.0",
|
|
48
|
-
"markdown-it": "14.1.0",
|
|
49
|
-
"pg": "8.11.3",
|
|
50
|
-
"pino": "9.5.0",
|
|
51
|
-
"pino-abstract-transport": "2.0.0",
|
|
52
|
-
"promised-handlebars": "2.0.1",
|
|
53
|
-
"qrcode": "1.5.4",
|
|
54
|
-
"uglify-js": "3.19.3"
|
|
55
|
-
},
|
|
56
|
-
"devDependencies": {
|
|
57
|
-
"eslint": "^8.49.0",
|
|
58
|
-
"eslint-config-airbnb": "^19.0.4"
|
|
59
|
-
},
|
|
60
|
-
"author": "Softpro",
|
|
61
|
-
"license": "ISC"
|
|
1
|
+
{
|
|
2
|
+
"name": "@opengis/fastify-table",
|
|
3
|
+
"version": "1.4.71",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "core-plugins",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"fastify",
|
|
8
|
+
"table",
|
|
9
|
+
"crud",
|
|
10
|
+
"pg",
|
|
11
|
+
"backend"
|
|
12
|
+
],
|
|
13
|
+
"main": "index.js",
|
|
14
|
+
"files": [
|
|
15
|
+
"server/*",
|
|
16
|
+
"index.js",
|
|
17
|
+
"utils.js",
|
|
18
|
+
"config.js",
|
|
19
|
+
"dblist.js",
|
|
20
|
+
"redactionList.js"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
|
|
24
|
+
"test": "node --test",
|
|
25
|
+
"test:helpers": "node --test .\\test\\helpers",
|
|
26
|
+
"test:routes": "node --test .\\test\\routes",
|
|
27
|
+
"test:functions": "node --test .\\test\\functions",
|
|
28
|
+
"compress": "node compress.js",
|
|
29
|
+
"dev1": "set NODE_ENV=dev&& node server.js",
|
|
30
|
+
"dev": "node --env-file=.env.dev --env-file=.env server",
|
|
31
|
+
"start": "node --env-file=.env server"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@aws-sdk/client-s3": "3.554.0",
|
|
35
|
+
"@fastify/http-proxy": "11.1.2",
|
|
36
|
+
"@fastify/multipart": "9.0.3",
|
|
37
|
+
"@fastify/rate-limit": "10.3.0",
|
|
38
|
+
"@grpc/grpc-js": "1.10.6",
|
|
39
|
+
"@grpc/proto-loader": "0.7.12",
|
|
40
|
+
"better-sqlite3": "12.2.0",
|
|
41
|
+
"dotenv": "16.5.0",
|
|
42
|
+
"fastify": "5.3.3",
|
|
43
|
+
"fastify-plugin": "5.0.1",
|
|
44
|
+
"handlebars": "4.7.8",
|
|
45
|
+
"image-size": "1.2.0",
|
|
46
|
+
"ioredis": "5.3.2",
|
|
47
|
+
"js-yaml": "4.1.0",
|
|
48
|
+
"markdown-it": "14.1.0",
|
|
49
|
+
"pg": "8.11.3",
|
|
50
|
+
"pino": "9.5.0",
|
|
51
|
+
"pino-abstract-transport": "2.0.0",
|
|
52
|
+
"promised-handlebars": "2.0.1",
|
|
53
|
+
"qrcode": "1.5.4",
|
|
54
|
+
"uglify-js": "3.19.3"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"eslint": "^8.49.0",
|
|
58
|
+
"eslint-config-airbnb": "^19.0.4"
|
|
59
|
+
},
|
|
60
|
+
"author": "Softpro",
|
|
61
|
+
"license": "ISC"
|
|
62
62
|
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import setToken from '../../plugins/crud/funcs/setToken.js';
|
|
2
|
-
|
|
3
|
-
export default function tokenFunc(params) {
|
|
4
|
-
const { data, hash } = params;
|
|
5
|
-
|
|
6
|
-
if (!data?.root?.user?.uid && !hash.uid) return '-';
|
|
7
|
-
if (!hash || typeof hash !== 'object') return '-';
|
|
8
|
-
|
|
9
|
-
// const id = hash?.edit ? hash?.id : data?.root?.id;
|
|
10
|
-
// console.log(hash)
|
|
11
|
-
const [token] = setToken({
|
|
12
|
-
ids: [JSON.stringify(hash)],
|
|
13
|
-
|
|
14
|
-
uid: data?.root?.user?.uid || hash.uid,
|
|
15
|
-
array: 1,
|
|
16
|
-
});
|
|
17
|
-
return token;
|
|
18
|
-
}
|
|
1
|
+
import setToken from '../../plugins/crud/funcs/setToken.js';
|
|
2
|
+
|
|
3
|
+
export default function tokenFunc(params) {
|
|
4
|
+
const { data, hash } = params;
|
|
5
|
+
|
|
6
|
+
if (!data?.root?.user?.uid && !hash.uid) return '-';
|
|
7
|
+
if (!hash || typeof hash !== 'object') return '-';
|
|
8
|
+
|
|
9
|
+
// const id = hash?.edit ? hash?.id : data?.root?.id;
|
|
10
|
+
// console.log(hash)
|
|
11
|
+
const [token] = setToken({
|
|
12
|
+
ids: [JSON.stringify(hash)],
|
|
13
|
+
|
|
14
|
+
uid: data?.root?.user?.uid || hash.uid,
|
|
15
|
+
array: 1,
|
|
16
|
+
});
|
|
17
|
+
return token;
|
|
18
|
+
}
|
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
import config from '../../../../config.js';
|
|
2
|
-
|
|
3
|
-
import logger from '../../logger/getLogger.js';
|
|
4
|
-
import pgClients from '../../pg/pgClients.js';
|
|
5
|
-
|
|
6
|
-
import cronList from '../cronList.js';
|
|
7
|
-
import runCron from './runCron.js';
|
|
8
|
-
import interval2ms from './interval2ms.js';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* interval:
|
|
12
|
-
* - 02:54 - every day
|
|
13
|
-
* - 2:03 - every day
|
|
14
|
-
* - *1:43 - 2 times a day
|
|
15
|
-
* - *12:03 - 2 times a day
|
|
16
|
-
* - **:54 - every hour
|
|
17
|
-
* - **:*3 - every 10 minutes
|
|
18
|
-
* - 60 - every minute
|
|
19
|
-
* - 10 * 60 - every 10 minutes
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
export default async function addCron(func, interval, pg = pgClients.client) {
|
|
23
|
-
const { time = {}, disabled = [] } = config.cron || {};
|
|
24
|
-
|
|
25
|
-
const name = func.name || func.toString().split('/').at(-1).split('\'')[0];
|
|
26
|
-
|
|
27
|
-
// if (!config.isServer) return;
|
|
28
|
-
|
|
29
|
-
if (disabled.includes(name)) {
|
|
30
|
-
logger.file('cron', { name, message: 'cron disabled' });
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
cronList[name] = func;
|
|
35
|
-
|
|
36
|
-
const userInterval = time[name] || interval;
|
|
37
|
-
const [waitMs, intervalMs] = interval2ms[typeof interval](userInterval);
|
|
38
|
-
|
|
39
|
-
if (intervalMs < 1000) {
|
|
40
|
-
logger.file('cron', { name, error: `interval ${interval} too small` });
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// setTimeout to w8 for the time to start
|
|
45
|
-
setTimeout(() => {
|
|
46
|
-
runCron({ pg, func, name });
|
|
47
|
-
// interval
|
|
48
|
-
setInterval(() => {
|
|
49
|
-
runCron({ pg, func, name });
|
|
50
|
-
}, intervalMs);
|
|
51
|
-
}, waitMs);
|
|
52
|
-
}
|
|
1
|
+
import config from '../../../../config.js';
|
|
2
|
+
|
|
3
|
+
import logger from '../../logger/getLogger.js';
|
|
4
|
+
import pgClients from '../../pg/pgClients.js';
|
|
5
|
+
|
|
6
|
+
import cronList from '../cronList.js';
|
|
7
|
+
import runCron from './runCron.js';
|
|
8
|
+
import interval2ms from './interval2ms.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* interval:
|
|
12
|
+
* - 02:54 - every day
|
|
13
|
+
* - 2:03 - every day
|
|
14
|
+
* - *1:43 - 2 times a day
|
|
15
|
+
* - *12:03 - 2 times a day
|
|
16
|
+
* - **:54 - every hour
|
|
17
|
+
* - **:*3 - every 10 minutes
|
|
18
|
+
* - 60 - every minute
|
|
19
|
+
* - 10 * 60 - every 10 minutes
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
export default async function addCron(func, interval, pg = pgClients.client) {
|
|
23
|
+
const { time = {}, disabled = [] } = config.cron || {};
|
|
24
|
+
|
|
25
|
+
const name = func.name || func.toString().split('/').at(-1).split('\'')[0];
|
|
26
|
+
|
|
27
|
+
// if (!config.isServer) return;
|
|
28
|
+
|
|
29
|
+
if (disabled.includes(name)) {
|
|
30
|
+
logger.file('cron', { name, message: 'cron disabled' });
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
cronList[name] = func;
|
|
35
|
+
|
|
36
|
+
const userInterval = time[name] || interval;
|
|
37
|
+
const [waitMs, intervalMs] = interval2ms[typeof interval](userInterval);
|
|
38
|
+
|
|
39
|
+
if (intervalMs < 1000) {
|
|
40
|
+
logger.file('cron', { name, error: `interval ${interval} too small` });
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// setTimeout to w8 for the time to start
|
|
45
|
+
setTimeout(() => {
|
|
46
|
+
runCron({ pg, func, name });
|
|
47
|
+
// interval
|
|
48
|
+
setInterval(() => {
|
|
49
|
+
runCron({ pg, func, name });
|
|
50
|
+
}, intervalMs);
|
|
51
|
+
}, waitMs);
|
|
52
|
+
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import config from '../../../../config.js';
|
|
2
|
-
import getRedis from '../../redis/funcs/getRedis.js';
|
|
3
|
-
|
|
4
|
-
const rclient = getRedis({ db: 0 });
|
|
5
|
-
|
|
6
|
-
export default async function getOpt(token, uid = 0) {
|
|
7
|
-
if (!config.redis) return null;
|
|
8
|
-
|
|
9
|
-
const key = `opt:${uid}:${token}`;
|
|
10
|
-
// console.log(key);
|
|
11
|
-
const data = await rclient.get(key);
|
|
12
|
-
if (!data) return null;
|
|
13
|
-
return JSON.parse(data);
|
|
14
|
-
}
|
|
1
|
+
import config from '../../../../config.js';
|
|
2
|
+
import getRedis from '../../redis/funcs/getRedis.js';
|
|
3
|
+
|
|
4
|
+
const rclient = getRedis({ db: 0 });
|
|
5
|
+
|
|
6
|
+
export default async function getOpt(token, uid = 0) {
|
|
7
|
+
if (!config.redis) return null;
|
|
8
|
+
|
|
9
|
+
const key = `opt:${uid}:${token}`;
|
|
10
|
+
// console.log(key);
|
|
11
|
+
const data = await rclient.get(key);
|
|
12
|
+
if (!data) return null;
|
|
13
|
+
return JSON.parse(data);
|
|
14
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
|
|
3
|
-
import config from '../../../../../config.js';
|
|
4
|
-
|
|
5
|
-
export default function getFolder(req, type = 'server') {
|
|
6
|
-
if (!['server', 'local'].includes(type)) throw new Error('params type is invalid');
|
|
7
|
-
const types = { local: req.root || config.root, server: req.mapServerRoot || config.mapServerRoot };
|
|
8
|
-
const dbname = req.pg?.options?.database || req.pg?.database || config.pg?.database; // request / config params / default config params
|
|
9
|
-
const filepath = path.posix.join(types[type] || `/data/local/${dbname || ''}`, req.folder || config.folder || '');
|
|
10
|
-
return filepath;
|
|
11
|
-
}
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
|
|
3
|
+
import config from '../../../../../config.js';
|
|
4
|
+
|
|
5
|
+
export default function getFolder(req, type = 'server') {
|
|
6
|
+
if (!['server', 'local'].includes(type)) throw new Error('params type is invalid');
|
|
7
|
+
const types = { local: req.root || config.root, server: req.mapServerRoot || config.mapServerRoot };
|
|
8
|
+
const dbname = req.pg?.options?.database || req.pg?.database || config.pg?.database; // request / config params / default config params
|
|
9
|
+
const filepath = path.posix.join(types[type] || `/data/local/${dbname || ''}`, req.folder || config.folder || '');
|
|
10
|
+
return filepath;
|
|
11
|
+
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import applyHookSync from '../hook/funcs/applyHookSync.js';
|
|
2
|
-
|
|
3
|
-
function errorStatus(error) {
|
|
4
|
-
const hook = applyHookSync('errorStatus', error);
|
|
5
|
-
if (hook) return hook;
|
|
6
|
-
|
|
7
|
-
if (error.routine === 'exec_stmt_raise' && error.file === 'pl_exec.c') {
|
|
8
|
-
return 601;
|
|
9
|
-
}
|
|
10
|
-
if (error.routine === 'ExecConstraints') {
|
|
11
|
-
return 602;
|
|
12
|
-
}
|
|
13
|
-
if (error.type === 'DatabaseError') {
|
|
14
|
-
return 600;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return 500;
|
|
18
|
-
}
|
|
19
|
-
export default errorStatus;
|
|
1
|
+
import applyHookSync from '../hook/funcs/applyHookSync.js';
|
|
2
|
+
|
|
3
|
+
function errorStatus(error) {
|
|
4
|
+
const hook = applyHookSync('errorStatus', error);
|
|
5
|
+
if (hook) return hook;
|
|
6
|
+
|
|
7
|
+
if (error.routine === 'exec_stmt_raise' && error.file === 'pl_exec.c') {
|
|
8
|
+
return 601;
|
|
9
|
+
}
|
|
10
|
+
if (error.routine === 'ExecConstraints') {
|
|
11
|
+
return 602;
|
|
12
|
+
}
|
|
13
|
+
if (error.type === 'DatabaseError') {
|
|
14
|
+
return 600;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return 500;
|
|
18
|
+
}
|
|
19
|
+
export default errorStatus;
|
|
@@ -28,7 +28,7 @@ export default async function execMigrations(dirPath, pg = pgClients.client, isc
|
|
|
28
28
|
return txt;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
if (process.env.NODE_ENV !== 'production' && (
|
|
31
|
+
if (process.env.NODE_ENV !== 'production' && !(iscore ? config.migrationsCore : config.migrations)) {
|
|
32
32
|
const txt = `migrations skip: not a production environment - ${iscore ? 'core' : 'path'} : ${dirPath}`;
|
|
33
33
|
if (debug) console.log(txt);
|
|
34
34
|
return txt;
|
|
@@ -3,9 +3,9 @@ import config from '../../../../config.js';
|
|
|
3
3
|
import pgClient from '../pgClients.js';
|
|
4
4
|
|
|
5
5
|
// subfunc
|
|
6
|
-
const getTable = ({ table }) => table
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
const getTable = ({ table }) => table?.toLowerCase?.()?.replace?.(/[\n\r]+/g, ' ')?.split?.(' from ')
|
|
7
|
+
?.filter((el) => /^[a-z0-9_]+\.[a-z0-9_]+/.test(el))
|
|
8
|
+
?.map((el) => el?.split?.(/[ )]/)?.[0]);
|
|
9
9
|
|
|
10
10
|
const loadedIndex = {};
|
|
11
11
|
|
|
@@ -27,8 +27,8 @@ async function autoIndex({
|
|
|
27
27
|
if (existsCache && !config.disableCache) { return 'ok'; }
|
|
28
28
|
|
|
29
29
|
const tbs = tableList[0];
|
|
30
|
-
const [ns, tbl] = tableList[0]
|
|
31
|
-
const { rows: index } = await pg.query(
|
|
30
|
+
const [ns, tbl] = tableList[0]?.split?.('.') || [];
|
|
31
|
+
const { rows: index } = tbl ? await pg.query('select * from pg_indexes where tablename = $1 and schemaname = $2', [tbl, ns]) : {};
|
|
32
32
|
|
|
33
33
|
if (existsCache && !config.disableCache && index?.length > 0) { return null; }
|
|
34
34
|
// console.log('autoindex', table, filter?.map((el) => el.name || el));
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import redisClients from './funcs/redisClients.js';
|
|
2
|
-
import getRedis from './funcs/getRedis.js';
|
|
3
|
-
|
|
4
|
-
if (!redisClients[0]) {
|
|
5
|
-
getRedis({ db: 0 });
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export default redisClients[0];
|
|
1
|
+
import redisClients from './funcs/redisClients.js';
|
|
2
|
+
import getRedis from './funcs/getRedis.js';
|
|
3
|
+
|
|
4
|
+
if (!redisClients[0]) {
|
|
5
|
+
getRedis({ db: 0 });
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export default redisClients[0];
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
const redisClients = {};
|
|
2
|
-
|
|
3
|
-
export default redisClients;
|
|
1
|
+
const redisClients = {};
|
|
2
|
+
|
|
3
|
+
export default redisClients;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
async function getCustomQuery({
|
|
2
|
-
pg, table, customFilter,
|
|
3
|
-
}) {
|
|
4
|
-
if (!customFilter) return null;
|
|
5
|
-
const customFilterList = customFilter?.split(',')?.map((el) => el?.split('_').pop());
|
|
6
|
-
const { property_json: customFilterSQL } = await pg.one(`select json_agg(json_build_object('id',property_id,'name',property_key,'query',property_text)
|
|
7
|
-
) as property_json from admin.properties where property_key is not null and property_entity='customQuery' and object_id=$1`, [table]);
|
|
8
|
-
const data = customFilterSQL?.length ? customFilterSQL.filter((el) => customFilterList.includes(el.id)) || [] : [];
|
|
9
|
-
const customQuery = data?.map((el) => el.query).join(' and ');
|
|
10
|
-
return `${customQuery}`;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export default getCustomQuery;
|
|
1
|
+
async function getCustomQuery({
|
|
2
|
+
pg, table, customFilter,
|
|
3
|
+
}) {
|
|
4
|
+
if (!customFilter) return null;
|
|
5
|
+
const customFilterList = customFilter?.split(',')?.map((el) => el?.split('_').pop());
|
|
6
|
+
const { property_json: customFilterSQL } = await pg.one(`select json_agg(json_build_object('id',property_id,'name',property_key,'query',property_text)
|
|
7
|
+
) as property_json from admin.properties where property_key is not null and property_entity='customQuery' and object_id=$1`, [table]);
|
|
8
|
+
const data = customFilterSQL?.length ? customFilterSQL.filter((el) => customFilterList.includes(el.id)) || [] : [];
|
|
9
|
+
const customQuery = data?.map((el) => el.query).join(' and ');
|
|
10
|
+
return `${customQuery}`;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export default getCustomQuery;
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
function getTable(table) {
|
|
2
|
-
const result = table?.toLowerCase()?.replace(/[\n\r]+/g, ' ')?.split(' from ')?.filter((el) => /^[a-z0-9_]+\.[a-z0-9_]+/.test(el))
|
|
3
|
-
?.map((el) => el.split(/[ )]/)[0]);
|
|
4
|
-
return result;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @param {Number} opt.json - (1|0) 1 - Результат - Object, 0 - String
|
|
9
|
-
* @param {String} opt.query - запит до таблиці
|
|
10
|
-
* @param {String} opt.hash - інформація з хешу по запиту
|
|
11
|
-
*/
|
|
12
|
-
const tableSql = {};
|
|
13
|
-
async function getTableSql({
|
|
14
|
-
pg, body, table, fields,
|
|
15
|
-
}) {
|
|
16
|
-
if (tableSql[table]) return tableSql[table];
|
|
17
|
-
|
|
18
|
-
const fieldList = fields.map((el) => el.name);
|
|
19
|
-
|
|
20
|
-
const tableList = body?.sql?.map((el) => getTable(el.sql)).reduce((acc, el) => acc.concat(el), []).filter((el) => fieldList.includes(pg.pk[el]));
|
|
21
|
-
|
|
22
|
-
if (!tableList) { tableSql[table] = []; return []; }
|
|
23
|
-
|
|
24
|
-
const data = await Promise.all(tableList?.map(async (tableEl) => {
|
|
25
|
-
const { fields: fieldsEl } = await pg.query(`select * from ${tableEl} limit 0`);
|
|
26
|
-
return fieldsEl.map((el) => ({ name: el.name, table: tableEl, pk: pg.pk[tableEl] }));
|
|
27
|
-
}));
|
|
28
|
-
|
|
29
|
-
tableSql[table] = data.reduce((acc, el) => acc.concat(el), []);
|
|
30
|
-
|
|
31
|
-
return tableSql[table];
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export default getTableSql;
|
|
1
|
+
function getTable(table) {
|
|
2
|
+
const result = table?.toLowerCase()?.replace(/[\n\r]+/g, ' ')?.split(' from ')?.filter((el) => /^[a-z0-9_]+\.[a-z0-9_]+/.test(el))
|
|
3
|
+
?.map((el) => el.split(/[ )]/)[0]);
|
|
4
|
+
return result;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @param {Number} opt.json - (1|0) 1 - Результат - Object, 0 - String
|
|
9
|
+
* @param {String} opt.query - запит до таблиці
|
|
10
|
+
* @param {String} opt.hash - інформація з хешу по запиту
|
|
11
|
+
*/
|
|
12
|
+
const tableSql = {};
|
|
13
|
+
async function getTableSql({
|
|
14
|
+
pg, body, table, fields,
|
|
15
|
+
}) {
|
|
16
|
+
if (tableSql[table]) return tableSql[table];
|
|
17
|
+
|
|
18
|
+
const fieldList = fields.map((el) => el.name);
|
|
19
|
+
|
|
20
|
+
const tableList = body?.sql?.map((el) => getTable(el.sql)).reduce((acc, el) => acc.concat(el), []).filter((el) => fieldList.includes(pg.pk[el]));
|
|
21
|
+
|
|
22
|
+
if (!tableList) { tableSql[table] = []; return []; }
|
|
23
|
+
|
|
24
|
+
const data = await Promise.all(tableList?.map(async (tableEl) => {
|
|
25
|
+
const { fields: fieldsEl } = await pg.query(`select * from ${tableEl} limit 0`);
|
|
26
|
+
return fieldsEl.map((el) => ({ name: el.name, table: tableEl, pk: pg.pk[tableEl] }));
|
|
27
|
+
}));
|
|
28
|
+
|
|
29
|
+
tableSql[table] = data.reduce((acc, el) => acc.concat(el), []);
|
|
30
|
+
|
|
31
|
+
return tableSql[table];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export default getTableSql;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
|
|
4
|
-
import config from '../../../../config.js';
|
|
5
|
-
|
|
6
|
-
const loadTemplate = {};
|
|
7
|
-
|
|
8
|
-
export default async function getTemplateDir(type) {
|
|
9
|
-
if (!type) return null;
|
|
10
|
-
|
|
11
|
-
const cwd = process.cwd();
|
|
12
|
-
const typeDir = path.join(cwd, (config.templateDir || 'server/templates'), type);
|
|
13
|
-
|
|
14
|
-
if (!loadTemplate[type]) {
|
|
15
|
-
const typeList = fs.existsSync(typeDir) ? fs.readdirSync(typeDir) : [];
|
|
16
|
-
loadTemplate[type] = typeList;
|
|
17
|
-
}
|
|
18
|
-
return loadTemplate[type];
|
|
19
|
-
}
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
4
|
+
import config from '../../../../config.js';
|
|
5
|
+
|
|
6
|
+
const loadTemplate = {};
|
|
7
|
+
|
|
8
|
+
export default async function getTemplateDir(type) {
|
|
9
|
+
if (!type) return null;
|
|
10
|
+
|
|
11
|
+
const cwd = process.cwd();
|
|
12
|
+
const typeDir = path.join(cwd, (config.templateDir || 'server/templates'), type);
|
|
13
|
+
|
|
14
|
+
if (!loadTemplate[type]) {
|
|
15
|
+
const typeList = fs.existsSync(typeDir) ? fs.readdirSync(typeDir) : [];
|
|
16
|
+
loadTemplate[type] = typeList;
|
|
17
|
+
}
|
|
18
|
+
return loadTemplate[type];
|
|
19
|
+
}
|