@opengis/fastify-table 1.1.74 → 1.1.75
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
CHANGED
|
@@ -103,40 +103,40 @@ CREATE INDEX IF NOT EXISTS admin_user_roles_role_id_idx ON admin.user_roles USIN
|
|
|
103
103
|
|
|
104
104
|
|
|
105
105
|
-- Route (Interface) <> User / Role (Group)
|
|
106
|
-
-- drop table if exists admin.
|
|
107
|
-
CREATE TABLE if not exists admin.
|
|
108
|
-
alter table admin.
|
|
109
|
-
alter table admin.
|
|
110
|
-
alter table admin.
|
|
111
|
-
alter table admin.
|
|
112
|
-
|
|
113
|
-
alter table admin.
|
|
114
|
-
alter table admin.
|
|
115
|
-
alter table admin.
|
|
116
|
-
alter table admin.
|
|
117
|
-
alter table admin.
|
|
118
|
-
alter table admin.
|
|
119
|
-
ALTER TABLE admin.
|
|
120
|
-
ALTER TABLE admin.
|
|
121
|
-
alter table admin.
|
|
122
|
-
alter table admin.
|
|
123
|
-
alter table admin.
|
|
124
|
-
alter table admin.
|
|
125
|
-
|
|
126
|
-
alter table admin.
|
|
106
|
+
-- drop table if exists admin.role_access;
|
|
107
|
+
CREATE TABLE if not exists admin.role_access();
|
|
108
|
+
alter table admin.role_access DROP CONSTRAINT if exists admin_access_id_pkey;
|
|
109
|
+
alter table admin.role_access DROP CONSTRAINT if exists admin_access_role_id_fkey;
|
|
110
|
+
alter table admin.role_access DROP CONSTRAINT if exists admin_access_route_id_uid_unique;
|
|
111
|
+
alter table admin.role_access DROP CONSTRAINT if exists admin_access_route_id_fkey;
|
|
112
|
+
|
|
113
|
+
alter table admin.role_access add column if not exists access_id text NOT NULL DEFAULT next_id();
|
|
114
|
+
alter table admin.role_access add column if not exists route_id text NOT NULL;
|
|
115
|
+
alter table admin.role_access add column if not exists role_id text;
|
|
116
|
+
alter table admin.role_access add column if not exists user_uid text;
|
|
117
|
+
alter table admin.role_access add column if not exists scope text;
|
|
118
|
+
alter table admin.role_access add column if not exists actions text[];
|
|
119
|
+
ALTER TABLE admin.role_access ADD COLUMN IF NOT EXISTS access_granted text;
|
|
120
|
+
ALTER TABLE admin.role_access ADD COLUMN IF NOT EXISTS access_granted_time timestamp without time zone;
|
|
121
|
+
alter table admin.role_access add column if not exists cdate timestamp without time zone NOT NULL DEFAULT date_trunc('seconds'::text, now());
|
|
122
|
+
alter table admin.role_access add column if not exists uid text;
|
|
123
|
+
alter table admin.role_access add column if not exists editor_id text;
|
|
124
|
+
alter table admin.role_access add column if not exists editor_date timestamp without time zone;
|
|
125
|
+
|
|
126
|
+
alter table admin.role_access
|
|
127
127
|
add CONSTRAINT admin_access_id_pkey PRIMARY KEY (access_id);
|
|
128
128
|
|
|
129
|
-
COMMENT ON TABLE admin.
|
|
130
|
-
COMMENT ON COLUMN admin.
|
|
131
|
-
COMMENT ON COLUMN admin.
|
|
132
|
-
COMMENT ON COLUMN admin.
|
|
133
|
-
COMMENT ON COLUMN admin.
|
|
134
|
-
COMMENT ON COLUMN admin.
|
|
135
|
-
COMMENT ON COLUMN admin.
|
|
136
|
-
COMMENT ON COLUMN admin.
|
|
129
|
+
COMMENT ON TABLE admin.role_access IS 'Налаштування прав. Відношення груп / окремих користувачів до шаблонів';
|
|
130
|
+
COMMENT ON COLUMN admin.role_access.route_id IS 'ID шаблона';
|
|
131
|
+
COMMENT ON COLUMN admin.role_access.role_id IS 'ID групи';
|
|
132
|
+
COMMENT ON COLUMN admin.role_access.user_uid IS 'ID користувача';
|
|
133
|
+
COMMENT ON COLUMN admin.role_access.scope IS 'Обмеження виведення (власні, відповідальний, всі)';
|
|
134
|
+
COMMENT ON COLUMN admin.role_access.actions IS 'Доступні дії';
|
|
135
|
+
COMMENT ON COLUMN admin.role_access.access_granted IS 'Ідентифікатор користувача який надав доступ';
|
|
136
|
+
COMMENT ON COLUMN admin.role_access.access_granted_time IS 'Час коли надали доступ';
|
|
137
137
|
|
|
138
|
-
CREATE INDEX if not exists admin_access_route_id_idx ON admin.
|
|
139
|
-
CREATE INDEX if not exists admin_access_role_id_idx ON admin.
|
|
138
|
+
CREATE INDEX if not exists admin_access_route_id_idx ON admin.role_access USING btree (route_id COLLATE pg_catalog."default");
|
|
139
|
+
CREATE INDEX if not exists admin_access_role_id_idx ON admin.role_access USING btree (role_id COLLATE pg_catalog."default");
|
|
140
140
|
|
|
141
141
|
-- Admin Menu
|
|
142
142
|
-- DROP TABLE if exists admin.menu;
|
|
@@ -161,13 +161,13 @@ COMMENT ON COLUMN admin.menu.name IS 'Назва пункту меню';
|
|
|
161
161
|
COMMENT ON COLUMN admin.menu.ord IS 'Порядковий номер';
|
|
162
162
|
COMMENT ON COLUMN admin.menu.enabled IS 'On / Off';
|
|
163
163
|
|
|
164
|
-
alter table admin.
|
|
164
|
+
alter table admin.role_access
|
|
165
165
|
add CONSTRAINT admin_access_role_id_fkey FOREIGN KEY (role_id) REFERENCES admin.roles (role_id);
|
|
166
166
|
alter table admin.routes add constraint admin_route_menu_id_fkey FOREIGN KEY (menu_id) REFERENCES admin.menu(menu_id);
|
|
167
167
|
|
|
168
|
-
alter table admin.
|
|
168
|
+
alter table admin.role_access
|
|
169
169
|
add CONSTRAINT admin_access_route_id_uid_unique UNIQUE (route_id, user_uid, role_id);
|
|
170
|
-
alter table admin.
|
|
170
|
+
alter table admin.role_access
|
|
171
171
|
add constraint admin_access_route_id_fkey FOREIGN KEY (route_id) REFERENCES admin.routes(route_id);
|
|
172
172
|
alter table admin.menu add CONSTRAINT admin_menu_name_unique UNIQUE (name);
|
|
173
173
|
ALTER TABLE admin.user_roles ADD CONSTRAINT admin_user_roles_user_role_id_fkey FOREIGN KEY (role_id) REFERENCES admin.roles (role_id);
|
|
@@ -8,7 +8,7 @@ import applyHook from '../../hook/funcs/applyHook.js';
|
|
|
8
8
|
|
|
9
9
|
const q = `select a.route_id as id, coalesce(b.actions,array['get']) as actions, b.scope
|
|
10
10
|
from admin.routes a
|
|
11
|
-
left join admin.
|
|
11
|
+
left join admin.role_access b on
|
|
12
12
|
a.route_id=b.route_id
|
|
13
13
|
left join admin.roles c on
|
|
14
14
|
b.role_id=c.role_id
|
|
@@ -19,7 +19,13 @@ const options = {
|
|
|
19
19
|
transport: {
|
|
20
20
|
targets: [{
|
|
21
21
|
target: './createFileStream.js', // path.resolve('utils/createFileStream.js')
|
|
22
|
-
}
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
level: 'error',
|
|
25
|
+
target: 'pino/file',
|
|
26
|
+
options: { destination: 1 },
|
|
27
|
+
},
|
|
28
|
+
],
|
|
23
29
|
},
|
|
24
30
|
};
|
|
25
31
|
const logger = pino(options);
|
|
@@ -16,14 +16,16 @@ export default async function getSelectMeta({ name, pg = pgClients.client, nocac
|
|
|
16
16
|
const { sql: original } = cls;
|
|
17
17
|
if (!original.toLowerCase) { console.log(`sql select null: ${name}`); return null; }
|
|
18
18
|
|
|
19
|
-
const sql = `with c(id,text) as (${original} ) select * from c
|
|
19
|
+
const sql = `with c(id,text) as (${original} ) select * from c`;
|
|
20
|
+
// large query > slow with() w/o limit
|
|
21
|
+
const sql1 = `with c(id,text) as (select * from (${original})q limit 0) select * from c`;
|
|
20
22
|
|
|
21
23
|
/*= == meta table === */
|
|
22
24
|
|
|
23
25
|
const tableNew = original.toLowerCase().replace(/\n/g, ' ').split(' from ').filter((el) => /^[a-z0-9_]+\.[a-z0-9_]+/.test(el))
|
|
24
26
|
.map((el) => el.split(/[ )]/)[0].replace(/[\r\n]+/g, ''));
|
|
25
27
|
|
|
26
|
-
const dataOrigin = await pg.query(`${
|
|
28
|
+
const dataOrigin = await pg.query(`${sql1} limit 0`);
|
|
27
29
|
|
|
28
30
|
const dataOrigin1 = await pg.query(`${original} limit 0`);
|
|
29
31
|
|
|
@@ -10,15 +10,12 @@ export default async function getSelectVal({ pg = pgClients.client, name, values
|
|
|
10
10
|
const key = `select:${name}`;
|
|
11
11
|
const cache = !cls.arr ? (await redis.hmget(key, values)).reduce((p, el, i) => ({ ...p, [values[i]]: el }), {}) : {};
|
|
12
12
|
|
|
13
|
-
const id = cls?.sql
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
const data = cls.arr || (values.filter(el => !cache[el]).length
|
|
17
|
-
? await pg.query(q).then(el => el.rows)
|
|
18
|
-
: []);
|
|
13
|
+
const { name: id } = cls?.sql ? await pg.queryCache(`select * from (${cls.sql})q limit 0`).then((res) => res.fields?.[0] || {}) : {};
|
|
14
|
+
const q = cls?.sql ? `with c(id,text) as (select * from (${cls.sql})q where ${id} = any('{${values.filter(el => !cache[el])}}')) select * from c` : '';
|
|
15
|
+
const data = (cls.sql && values.filter(el => !cache[el]).length ? await pg.query(q).then(el => el.rows) : cls?.arr?.filter((el) => values.filter(el => !cache[el])?.includes(el?.id))) || [];
|
|
19
16
|
|
|
20
17
|
const clsAr = { ...cache, ...data.reduce((p, el) => ({ ...p, [el.id.toString()]: el.color ? el : el.text }), {}) };
|
|
21
|
-
if (!cls.arr && data
|
|
18
|
+
if (!cls.arr && data?.length) {
|
|
22
19
|
redis.hmset(key, clsAr);
|
|
23
20
|
}
|
|
24
21
|
return clsAr;
|