@opengis/admin 0.3.21 → 0.3.22
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 +1 -1
- package/server/plugins/hook.js +5 -4
package/package.json
CHANGED
package/server/plugins/hook.js
CHANGED
@@ -119,27 +119,28 @@ export default async function plugin(fastify) {
|
|
119
119
|
|
120
120
|
try {
|
121
121
|
const hashes = await rclient.hgetall('cls-insert-hashes').then(obj => Object.keys(obj));
|
122
|
+
const names = await pgClients.client.query(`select array_agg(name) from admin.cls where parent is null`).then(el => el.rows?.[0]?.array_agg || []);
|
122
123
|
const qHashes = await Promise.all(cls.filter((el, idx, arr) => arr.map((item) => item.name).indexOf(el.name) === idx).map(async (el) => {
|
123
124
|
const { name, module, type } = el;
|
124
125
|
const loadTemplate = await getTemplate(type, name);
|
125
126
|
const hash = createHash('md5').update(type === 'cls' ? JSON.stringify(loadTemplate) : (loadTemplate?.sql || loadTemplate)).digest('hex');
|
126
|
-
if (type === 'select' && !hashes.includes(hash)) {
|
127
|
+
if (type === 'select' && (!hashes.includes(hash) || !names.includes(name))) {
|
127
128
|
clsQuery.push(`insert into admin.cls(name,type,data,module) values('${name}','sql','${(loadTemplate?.sql || loadTemplate)?.replace(/'/g, "''")}', '${module?.replace(/'/g, "''")}')`);
|
128
129
|
return hash;
|
129
|
-
} else if (type === 'cls' && loadTemplate?.length && !hashes.includes(hash)) {
|
130
|
+
} else if (type === 'cls' && loadTemplate?.length && (!hashes.includes(hash) || !names.includes(name))) {
|
130
131
|
clsQuery.push(`insert into admin.cls(name,type, module) values('${name}','json', '${module?.replace(/'/g, "''")}');
|
131
132
|
insert into admin.cls(code,name,parent,icon,data)
|
132
133
|
select value->>'id',value->>'text','${name}',value->>'icon',value->>'data'
|
133
134
|
from json_array_elements('${JSON.stringify(loadTemplate).replace(/'/g, "''")}'::json)`);
|
134
135
|
return hash;
|
135
136
|
} else if (hashes.includes(hash)) {
|
136
|
-
console.log(name, type, 'skip equal hash');
|
137
|
+
console.log(name, type, names.includes(name) ? 'skip equal hash' : 'insert missing cls');
|
137
138
|
} else {
|
138
139
|
console.log(name, type, 'empty');
|
139
140
|
}
|
140
141
|
}));
|
141
142
|
|
142
|
-
const { rowCount = 0 } = await client.query('delete from admin.cls where name = any($1::text[])
|
143
|
+
const { rowCount = 0 } = await client.query('delete from admin.cls where not name = any($1::text[]) and (case when type = \'json\' then parent = any($1::text[]) else parent is null end)', [cls.map(el => el.name)]);
|
143
144
|
console.log('admin/hook old cls deleted', rowCount);
|
144
145
|
if (clsQuery.filter((el) => el).length) {
|
145
146
|
console.log('admin/hook cls sql start', clsQuery?.length);
|