@opengis/fastify-table 1.3.73 → 1.3.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/index.js +12 -6
- package/package.json +1 -1
- package/server/plugins/table/funcs/addMenu.js +16 -0
- package/server/plugins/table/funcs/addTemplateDir.js +1 -1
- package/server/plugins/table/funcs/menuDirs.js +1 -0
- package/server/routes/dblist/index.mjs +2 -3
- package/server/routes/menu/controllers/getMenu.js +7 -7
- package/utils.js +4 -0
package/index.js
CHANGED
|
@@ -35,9 +35,11 @@ import execMigrations from './server/plugins/migration/exec.migrations.js';
|
|
|
35
35
|
import locales from './server/routes/table/controllers/utils/locales.js';
|
|
36
36
|
import pgClients from './server/plugins/pg/pgClients.js';
|
|
37
37
|
|
|
38
|
-
import
|
|
39
|
-
|
|
40
|
-
import
|
|
38
|
+
import dblistRoutes from './server/routes/dblist/index.mjs';
|
|
39
|
+
|
|
40
|
+
import dataRoutes from './server/routes/data/index.mjs';
|
|
41
|
+
import menuRoutes from './server/routes/menu/index.mjs';
|
|
42
|
+
import templatesRoutes from './server/routes/templates/index.mjs';
|
|
41
43
|
|
|
42
44
|
// core templates && cls
|
|
43
45
|
const filename = fileURLToPath(import.meta.url);
|
|
@@ -99,6 +101,10 @@ async function plugin(fastify, opt) {
|
|
|
99
101
|
cronPlugin(fastify, opt);
|
|
100
102
|
loggerPlugin(fastify, opt);
|
|
101
103
|
|
|
104
|
+
if (config.dblist) {
|
|
105
|
+
dblistRoutes(fastify, opt);
|
|
106
|
+
}
|
|
107
|
+
|
|
102
108
|
// routes / api
|
|
103
109
|
cronRoutes(fastify, opt);
|
|
104
110
|
crudRoutes(fastify, opt);
|
|
@@ -107,9 +113,9 @@ async function plugin(fastify, opt) {
|
|
|
107
113
|
tableRoutes(fastify, opt);
|
|
108
114
|
utilRoutes(fastify, opt);
|
|
109
115
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
116
|
+
dataRoutes(fastify, opt);
|
|
117
|
+
menuRoutes(fastify, opt);
|
|
118
|
+
templatesRoutes(fastify, opt);
|
|
113
119
|
|
|
114
120
|
fastify.get('/api/test-proxy', {}, (req) => ({ ...req.headers || {}, sessionId: req.session?.sessionId }));
|
|
115
121
|
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { basename } from 'node:path';
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
|
|
4
|
+
import menuDirs from './menuDirs.js';
|
|
5
|
+
|
|
6
|
+
export default function addMenu(filepath) {
|
|
7
|
+
if (basename(filepath) !== 'menu.json') {
|
|
8
|
+
throw new Error('addMenu: filepath must be a menu.json file');
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
if (filepath && !menuDirs.includes(filepath) && existsSync(filepath)) {
|
|
12
|
+
menuDirs.push(filepath);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return menuDirs;
|
|
16
|
+
}
|
|
@@ -2,7 +2,7 @@ import { existsSync, readFileSync } from 'node:fs';
|
|
|
2
2
|
|
|
3
3
|
import userTemplateDir from './userTemplateDir.js';
|
|
4
4
|
import customTokens from './customTokens.js';
|
|
5
|
-
import yml2json from '../../yml/funcs/yml2json.js'
|
|
5
|
+
import yml2json from '../../yml/funcs/yml2json.js';
|
|
6
6
|
|
|
7
7
|
export default function addTemplateDir(dir) {
|
|
8
8
|
if (dir && !userTemplateDir.includes(dir)) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default [];
|
|
@@ -4,16 +4,15 @@ import setItem from './controllers/setItem.js';
|
|
|
4
4
|
const policy = ['site'];
|
|
5
5
|
|
|
6
6
|
export default async function plugin(app, config = {}) {
|
|
7
|
-
const { prefix = '/api' } = config;
|
|
8
7
|
app.route({
|
|
9
8
|
method: 'GET',
|
|
10
|
-
url:
|
|
9
|
+
url: '/db-list',
|
|
11
10
|
config: { policy },
|
|
12
11
|
handler: readItemList,
|
|
13
12
|
});
|
|
14
13
|
app.route({
|
|
15
14
|
method: 'GET',
|
|
16
|
-
url:
|
|
15
|
+
url: '/db-list/:id',
|
|
17
16
|
config: { policy },
|
|
18
17
|
handler: setItem,
|
|
19
18
|
});
|
|
@@ -5,7 +5,7 @@ import { join } from 'node:path';
|
|
|
5
5
|
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
6
6
|
|
|
7
7
|
import {
|
|
8
|
-
|
|
8
|
+
menuDirs, pgClients, applyHook, config,
|
|
9
9
|
} from '../../../../utils.js';
|
|
10
10
|
|
|
11
11
|
const menuCache = [];
|
|
@@ -13,17 +13,16 @@ const menuCache = [];
|
|
|
13
13
|
// check module dir
|
|
14
14
|
const moduleDir = join(process.cwd(), 'module');
|
|
15
15
|
const dirs = existsSync(moduleDir)
|
|
16
|
-
? readdirSync(moduleDir).map(el => join(moduleDir, el))
|
|
16
|
+
? readdirSync(moduleDir).map(el => join(moduleDir, el, 'menu.json'))
|
|
17
17
|
: [];
|
|
18
18
|
|
|
19
19
|
const isProduction = process.env.NODE_ENV === 'production';
|
|
20
20
|
// readMenu();
|
|
21
21
|
|
|
22
22
|
async function readMenu() {
|
|
23
|
-
const menuList = dirs.concat(
|
|
24
|
-
.map(el => join(el, 'menu.json'))
|
|
23
|
+
const menuList = dirs.concat(menuDirs)
|
|
25
24
|
.filter(el => existsSync(el));
|
|
26
|
-
|
|
25
|
+
|
|
27
26
|
const list = menuList.filter((el, idx, arr) => el && arr.indexOf(el) === idx).map(el => readFileSync(el, 'utf-8')); // sync
|
|
28
27
|
const menus = list.reduce((p, el) => p.concat(JSON.parse(el)), [])
|
|
29
28
|
.map(el => ({ order: 0, ...el }))
|
|
@@ -32,11 +31,12 @@ async function readMenu() {
|
|
|
32
31
|
if (!menuCache.length) {
|
|
33
32
|
menus.forEach(el => menuCache.push(el));
|
|
34
33
|
}
|
|
35
|
-
|
|
36
34
|
return menus;
|
|
37
35
|
}
|
|
38
36
|
|
|
39
|
-
export default async function adminMenu({
|
|
37
|
+
export default async function adminMenu({
|
|
38
|
+
user = {}, session, pg = pgClients.client,
|
|
39
|
+
}, reply) {
|
|
40
40
|
const time = Date.now();
|
|
41
41
|
|
|
42
42
|
if (!user.uid) {
|
package/utils.js
CHANGED
|
@@ -23,6 +23,8 @@ import getTemplateSync from './server/plugins/table/funcs/getTemplateSync.js';
|
|
|
23
23
|
import getTemplates from './server/plugins/table/funcs/getTemplates.js';
|
|
24
24
|
import getTemplatePath from './server/plugins/table/funcs/getTemplatePath.js';
|
|
25
25
|
import addTemplateDir from './server/plugins/table/funcs/addTemplateDir.js';
|
|
26
|
+
import addMenu from './server/plugins/table/funcs/addMenu.js';
|
|
27
|
+
import menuDirs from './server/plugins/table/funcs/menuDirs.js';
|
|
26
28
|
import userTemplateDir from './server/plugins/table/funcs/userTemplateDir.js';
|
|
27
29
|
import customTokens from './server/plugins/table/funcs/customTokens.js';
|
|
28
30
|
import userTokens from './server/plugins/table/funcs/userTokens.js';
|
|
@@ -110,6 +112,8 @@ export {
|
|
|
110
112
|
getTemplates,
|
|
111
113
|
getTemplatePath,
|
|
112
114
|
addTemplateDir,
|
|
115
|
+
menuDirs,
|
|
116
|
+
addMenu,
|
|
113
117
|
userTemplateDir,
|
|
114
118
|
customTokens,
|
|
115
119
|
userTokens,
|