@opengis/fastify-table 1.3.73 → 1.3.74
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
|
@@ -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 [];
|
|
@@ -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,
|