@opengis/fastify-table 1.2.19 → 1.2.20
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 +82 -79
- package/package.json +1 -1
- package/server/migrations/0.sql +84 -84
- package/server/migrations/properties.sql +184 -184
- package/server/migrations/template.sql +34 -34
- package/server/migrations/users.sql +175 -175
- package/server/plugins/crud/funcs/dataDelete.js +24 -24
- package/server/plugins/crud/funcs/dataInsert.js +53 -53
- package/server/plugins/crud/funcs/dataUpdate.js +65 -65
- package/server/plugins/crud/funcs/utils/logChanges.js +118 -118
- package/server/plugins/logger/getLogger.js +13 -3
- package/server/plugins/metric/index.js +8 -0
- package/server/plugins/metric/loggerSystem.js +129 -0
- package/server/plugins/metric/systemMetricsFifthly.js +23 -0
- package/server/plugins/migration/exec.migrations.js +37 -37
- package/server/plugins/policy/index.js +12 -12
- package/server/plugins/table/funcs/getFilterSQL/util/formatValue.js +179 -179
- package/server/plugins/table/funcs/getFilterSQL/util/getFilterQuery.js +66 -66
- package/server/plugins/table/funcs/metaFormat/getSelectVal.js +50 -50
- package/server/plugins/table/funcs/metaFormat/index.js +45 -45
- package/server/routes/crud/controllers/deleteCrud.js +39 -39
- package/server/routes/table/controllers/filter.js +67 -67
- package/server/routes/table/controllers/suggest.js +166 -166
- package/utils.js +129 -129
package/index.js
CHANGED
|
@@ -1,79 +1,82 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import fp from 'fastify-plugin';
|
|
3
|
-
import { fileURLToPath } from 'node:url';
|
|
4
|
-
|
|
5
|
-
import config from './config.js';
|
|
6
|
-
|
|
7
|
-
// plugins
|
|
8
|
-
import cronPlugin from './server/plugins/cron/index.js';
|
|
9
|
-
import crudPlugin from './server/plugins/crud/index.js';
|
|
10
|
-
// hook, logger, migration - utils only
|
|
11
|
-
import pgPlugin from './server/plugins/pg/index.js';
|
|
12
|
-
import policyPlugin from './server/plugins/policy/index.js';
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
import
|
|
21
|
-
import
|
|
22
|
-
import
|
|
23
|
-
import
|
|
24
|
-
import
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import fp from 'fastify-plugin';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
|
|
5
|
+
import config from './config.js';
|
|
6
|
+
|
|
7
|
+
// plugins
|
|
8
|
+
import cronPlugin from './server/plugins/cron/index.js';
|
|
9
|
+
import crudPlugin from './server/plugins/crud/index.js';
|
|
10
|
+
// hook, logger, migration - utils only
|
|
11
|
+
import pgPlugin from './server/plugins/pg/index.js';
|
|
12
|
+
import policyPlugin from './server/plugins/policy/index.js';
|
|
13
|
+
import metricPlugin from './server/plugins/metric/index.js';
|
|
14
|
+
import redisPlugin from './server/plugins/redis/index.js';
|
|
15
|
+
import tablePlugin from './server/plugins/table/index.js';
|
|
16
|
+
import utilPlugin from './server/plugins/util/index.js';
|
|
17
|
+
import loggerPlugin from './server/plugins/logger/index.js';
|
|
18
|
+
|
|
19
|
+
// routes
|
|
20
|
+
import cronRoutes from './server/routes/cron/index.js';
|
|
21
|
+
import crudRoutes from './server/routes/crud/index.js';
|
|
22
|
+
import loggerRoutes from './server/routes/logger/index.js';
|
|
23
|
+
import propertiesRoutes from './server/routes/properties/index.js';
|
|
24
|
+
import tableRoutes from './server/routes/table/index.js';
|
|
25
|
+
import utilRoutes from './server/routes/util/index.js';
|
|
26
|
+
|
|
27
|
+
import {
|
|
28
|
+
addTemplateDir, execMigrations,
|
|
29
|
+
} from './utils.js';
|
|
30
|
+
|
|
31
|
+
// core templates && cls
|
|
32
|
+
const filename = fileURLToPath(import.meta.url);
|
|
33
|
+
const cwd = path.dirname(filename);
|
|
34
|
+
|
|
35
|
+
async function plugin(fastify, opt) {
|
|
36
|
+
config.pg = opt.pg;
|
|
37
|
+
config.redis = opt.redis;
|
|
38
|
+
config.root = opt.root;
|
|
39
|
+
config.mapServerRoot = opt.mapServerRoot;
|
|
40
|
+
|
|
41
|
+
// independent npm start / unit test
|
|
42
|
+
if (!fastify.config) {
|
|
43
|
+
fastify.decorate('config', config);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
fastify.register(import('@fastify/sensible'), {
|
|
47
|
+
errorHandler: false,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
fastify.register(import('@fastify/url-data'), {
|
|
51
|
+
errorHandler: false,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
fastify.register(import('@opengis/fastify-hb'));
|
|
55
|
+
|
|
56
|
+
// core migrations (second argument for core only)
|
|
57
|
+
execMigrations(path.join(cwd, 'server/migrations'), true).catch(err => console.log(err));
|
|
58
|
+
|
|
59
|
+
// core templates && cls
|
|
60
|
+
config.templates?.forEach(el => addTemplateDir(el));
|
|
61
|
+
addTemplateDir(path.join(cwd, 'module/core'));
|
|
62
|
+
|
|
63
|
+
// plugins / utils / funcs
|
|
64
|
+
policyPlugin(fastify);
|
|
65
|
+
metricPlugin(fastify);
|
|
66
|
+
redisPlugin(fastify);
|
|
67
|
+
await pgPlugin(fastify, opt);
|
|
68
|
+
tablePlugin(fastify, opt);
|
|
69
|
+
crudPlugin(fastify, opt);
|
|
70
|
+
utilPlugin(fastify, opt);
|
|
71
|
+
cronPlugin(fastify, opt);
|
|
72
|
+
loggerPlugin(fastify, opt);
|
|
73
|
+
|
|
74
|
+
// routes / api
|
|
75
|
+
cronRoutes(fastify, opt);
|
|
76
|
+
crudRoutes(fastify, opt);
|
|
77
|
+
loggerRoutes(fastify, opt);
|
|
78
|
+
propertiesRoutes(fastify, opt);
|
|
79
|
+
tableRoutes(fastify, opt);
|
|
80
|
+
utilRoutes(fastify, opt);
|
|
81
|
+
}
|
|
82
|
+
export default fp(plugin);
|
package/package.json
CHANGED
package/server/migrations/0.sql
CHANGED
|
@@ -1,84 +1,84 @@
|
|
|
1
|
-
-- fix error if function exists and return type not text i.e bigint
|
|
2
|
-
|
|
3
|
-
do $$
|
|
4
|
-
|
|
5
|
-
declare
|
|
6
|
-
m record;
|
|
7
|
-
_pk text;
|
|
8
|
-
_tables json;
|
|
9
|
-
_returnType text;
|
|
10
|
-
|
|
11
|
-
begin
|
|
12
|
-
|
|
13
|
-
select format_type(p.prorettype, null) as return_type
|
|
14
|
-
from pg_proc p
|
|
15
|
-
where p.proname = 'next_id'
|
|
16
|
-
and p.pronamespace = 'public'::regnamespace into _returnType;
|
|
17
|
-
|
|
18
|
-
if (_returnType != 'text') then
|
|
19
|
-
raise notice 'default reassign start: % -> text', _returnType;
|
|
20
|
-
|
|
21
|
-
CREATE EXTENSION if not exists "uuid-ossp";
|
|
22
|
-
|
|
23
|
-
SELECT json_object_agg(a.attrelid::regclass, a.attname)
|
|
24
|
-
FROM pg_catalog.pg_attribute a
|
|
25
|
-
LEFT JOIN pg_catalog.pg_attrdef d ON (a.attrelid, a.attnum) = (d.adrelid, d.adnum)
|
|
26
|
-
WHERE NOT a.attisdropped -- no dropped (dead) columns
|
|
27
|
-
AND a.attnum > 0 -- no system columns
|
|
28
|
-
AND pg_get_expr(d.adbin, d.adrelid) = 'next_id()' into _tables;
|
|
29
|
-
|
|
30
|
-
FOR m in (select json_object_keys(_tables) as table) loop
|
|
31
|
-
_pk = _tables->>m.table;
|
|
32
|
-
raise notice 'drop default: %,%', m.table, _pk;
|
|
33
|
-
EXECUTE('alter table '|| m.table || ' alter column ' || _pk || ' set default null;');
|
|
34
|
-
end loop;
|
|
35
|
-
|
|
36
|
-
DROP FUNCTION IF EXISTS next_id();
|
|
37
|
-
|
|
38
|
-
/* CREATE EXTENSION if not exists "uuid-ossp";
|
|
39
|
-
ALTER EXTENSION "uuid-ossp" SET SCHEMA public; */
|
|
40
|
-
|
|
41
|
-
CREATE OR REPLACE FUNCTION next_id()
|
|
42
|
-
RETURNS text AS
|
|
43
|
-
$BODY$
|
|
44
|
-
DECLARE
|
|
45
|
-
|
|
46
|
-
BEGIN
|
|
47
|
-
-- return replace(public.uuid_generate_v4()::text, '-', '');
|
|
48
|
-
-- return replace(gen_random_uuid()::text, '-', ''); -- native from postgres 13 onward
|
|
49
|
-
return encode(public.gen_random_bytes(6), 'hex');
|
|
50
|
-
END;
|
|
51
|
-
$BODY$
|
|
52
|
-
LANGUAGE plpgsql VOLATILE
|
|
53
|
-
COST 100;
|
|
54
|
-
|
|
55
|
-
FOR m in (select json_object_keys(_tables) as table) loop
|
|
56
|
-
_pk = _tables->>m.table;
|
|
57
|
-
raise notice 'reassign default: %, %', m.table, _pk;
|
|
58
|
-
EXECUTE('alter table '|| m.table || ' alter column ' || _pk || ' set default next_id();');
|
|
59
|
-
end loop;
|
|
60
|
-
|
|
61
|
-
raise notice 'reassign default finish: %', _tables;
|
|
62
|
-
|
|
63
|
-
else
|
|
64
|
-
raise notice 'skip default reassign';
|
|
65
|
-
|
|
66
|
-
/* CREATE EXTENSION if not exists "uuid-ossp";
|
|
67
|
-
ALTER EXTENSION "uuid-ossp" SET SCHEMA public; */
|
|
68
|
-
|
|
69
|
-
CREATE OR REPLACE FUNCTION next_id()
|
|
70
|
-
RETURNS text AS
|
|
71
|
-
$BODY$
|
|
72
|
-
DECLARE
|
|
73
|
-
|
|
74
|
-
BEGIN
|
|
75
|
-
-- return replace(public.uuid_generate_v4()::text, '-', '');
|
|
76
|
-
-- return replace(gen_random_uuid()::text, '-', ''); -- native from postgres 13 onward
|
|
77
|
-
return encode(public.gen_random_bytes(6), 'hex');
|
|
78
|
-
END;
|
|
79
|
-
$BODY$
|
|
80
|
-
LANGUAGE plpgsql VOLATILE
|
|
81
|
-
COST 100;
|
|
82
|
-
end if;
|
|
83
|
-
|
|
84
|
-
end $$
|
|
1
|
+
-- fix error if function exists and return type not text i.e bigint
|
|
2
|
+
|
|
3
|
+
do $$
|
|
4
|
+
|
|
5
|
+
declare
|
|
6
|
+
m record;
|
|
7
|
+
_pk text;
|
|
8
|
+
_tables json;
|
|
9
|
+
_returnType text;
|
|
10
|
+
|
|
11
|
+
begin
|
|
12
|
+
|
|
13
|
+
select format_type(p.prorettype, null) as return_type
|
|
14
|
+
from pg_proc p
|
|
15
|
+
where p.proname = 'next_id'
|
|
16
|
+
and p.pronamespace = 'public'::regnamespace into _returnType;
|
|
17
|
+
|
|
18
|
+
if (_returnType != 'text') then
|
|
19
|
+
raise notice 'default reassign start: % -> text', _returnType;
|
|
20
|
+
|
|
21
|
+
CREATE EXTENSION if not exists "uuid-ossp";
|
|
22
|
+
|
|
23
|
+
SELECT json_object_agg(a.attrelid::regclass, a.attname)
|
|
24
|
+
FROM pg_catalog.pg_attribute a
|
|
25
|
+
LEFT JOIN pg_catalog.pg_attrdef d ON (a.attrelid, a.attnum) = (d.adrelid, d.adnum)
|
|
26
|
+
WHERE NOT a.attisdropped -- no dropped (dead) columns
|
|
27
|
+
AND a.attnum > 0 -- no system columns
|
|
28
|
+
AND pg_get_expr(d.adbin, d.adrelid) = 'next_id()' into _tables;
|
|
29
|
+
|
|
30
|
+
FOR m in (select json_object_keys(_tables) as table) loop
|
|
31
|
+
_pk = _tables->>m.table;
|
|
32
|
+
raise notice 'drop default: %,%', m.table, _pk;
|
|
33
|
+
EXECUTE('alter table '|| m.table || ' alter column ' || _pk || ' set default null;');
|
|
34
|
+
end loop;
|
|
35
|
+
|
|
36
|
+
DROP FUNCTION IF EXISTS next_id();
|
|
37
|
+
|
|
38
|
+
/* CREATE EXTENSION if not exists "uuid-ossp";
|
|
39
|
+
ALTER EXTENSION "uuid-ossp" SET SCHEMA public; */
|
|
40
|
+
|
|
41
|
+
CREATE OR REPLACE FUNCTION next_id()
|
|
42
|
+
RETURNS text AS
|
|
43
|
+
$BODY$
|
|
44
|
+
DECLARE
|
|
45
|
+
|
|
46
|
+
BEGIN
|
|
47
|
+
-- return replace(public.uuid_generate_v4()::text, '-', '');
|
|
48
|
+
-- return replace(gen_random_uuid()::text, '-', ''); -- native from postgres 13 onward
|
|
49
|
+
return encode(public.gen_random_bytes(6), 'hex');
|
|
50
|
+
END;
|
|
51
|
+
$BODY$
|
|
52
|
+
LANGUAGE plpgsql VOLATILE
|
|
53
|
+
COST 100;
|
|
54
|
+
|
|
55
|
+
FOR m in (select json_object_keys(_tables) as table) loop
|
|
56
|
+
_pk = _tables->>m.table;
|
|
57
|
+
raise notice 'reassign default: %, %', m.table, _pk;
|
|
58
|
+
EXECUTE('alter table '|| m.table || ' alter column ' || _pk || ' set default next_id();');
|
|
59
|
+
end loop;
|
|
60
|
+
|
|
61
|
+
raise notice 'reassign default finish: %', _tables;
|
|
62
|
+
|
|
63
|
+
else
|
|
64
|
+
raise notice 'skip default reassign';
|
|
65
|
+
|
|
66
|
+
/* CREATE EXTENSION if not exists "uuid-ossp";
|
|
67
|
+
ALTER EXTENSION "uuid-ossp" SET SCHEMA public; */
|
|
68
|
+
|
|
69
|
+
CREATE OR REPLACE FUNCTION next_id()
|
|
70
|
+
RETURNS text AS
|
|
71
|
+
$BODY$
|
|
72
|
+
DECLARE
|
|
73
|
+
|
|
74
|
+
BEGIN
|
|
75
|
+
-- return replace(public.uuid_generate_v4()::text, '-', '');
|
|
76
|
+
-- return replace(gen_random_uuid()::text, '-', ''); -- native from postgres 13 onward
|
|
77
|
+
return encode(public.gen_random_bytes(6), 'hex');
|
|
78
|
+
END;
|
|
79
|
+
$BODY$
|
|
80
|
+
LANGUAGE plpgsql VOLATILE
|
|
81
|
+
COST 100;
|
|
82
|
+
end if;
|
|
83
|
+
|
|
84
|
+
end $$
|