@opengis/fastify-table 1.1.49 → 1.1.51
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/.eslintrc.cjs +42 -42
- package/.gitlab-ci.yml +18 -0
- package/Changelog.md +352 -351
- package/cron/funcs/addCron.js +132 -132
- package/crud/controllers/deleteCrud.js +36 -31
- package/crud/controllers/insert.js +71 -70
- package/crud/controllers/update.js +76 -73
- package/crud/funcs/dataDelete.js +19 -19
- package/crud/funcs/dataInsert.js +30 -30
- package/crud/funcs/dataUpdate.js +48 -48
- package/crud/funcs/getAccess.js +46 -56
- package/crud/funcs/getOpt.js +10 -10
- package/crud/funcs/setOpt.js +16 -16
- package/crud/funcs/setToken.js +2 -2
- package/crud/funcs/utils/getFolder.js +9 -9
- package/crud/funcs/utils/logChanges.js +62 -62
- package/crud/index.js +36 -36
- package/docs/.vitepress/abbr.mjs +26 -26
- package/docs/.vitepress/config.mjs +127 -127
- package/docs/.vitepress/navigation.mjs +82 -82
- package/docs/.vitepress/theme/Layout.vue +17 -17
- package/docs/.vitepress/theme/components/NavigationLinks.vue +102 -102
- package/docs/.vitepress/theme/components/Panzoom.vue +169 -169
- package/docs/.vitepress/theme/index.mjs +15 -15
- package/docs/.vitepress/theme/style.scss +163 -163
- package/docs/abbr.json +4 -4
- package/docs/api/cron/cronApi.md +56 -56
- package/docs/api/crud/deleteCrud.md +58 -58
- package/docs/api/crud/insert.md +82 -82
- package/docs/api/crud/update.md +85 -85
- package/docs/api/index.md +47 -47
- package/docs/api/notification/testEmail.md +91 -91
- package/docs/api/table/card.md +73 -73
- package/docs/api/table/data.md +134 -134
- package/docs/api/table/export.md +60 -60
- package/docs/api/table/filter.md +104 -104
- package/docs/api/table/form.md +126 -126
- package/docs/api/table/search.md +123 -123
- package/docs/api/table/suggest.md +156 -156
- package/docs/api/table/table.md +107 -107
- package/docs/api/user/user.cls.id.md +77 -77
- package/docs/api/user/user.cls.md +49 -49
- package/docs/api/user/user.cls.post.md +62 -62
- package/docs/api/user/user.info.md +37 -37
- package/docs/api/utils/logger.file.md +60 -60
- package/docs/api/utils/next.id.md +34 -34
- package/docs/api/utils/properties.add.md +127 -127
- package/docs/api/utils/properties.get.md +73 -73
- package/docs/api/utils/status.monitor.md +36 -36
- package/docs/api/widget/widget.del.md +76 -76
- package/docs/api/widget/widget.get.md +233 -233
- package/docs/api/widget/widget.set.md +88 -88
- package/docs/db/admin.md +947 -947
- package/docs/db/crm.md +564 -564
- package/docs/db/index.md +9 -9
- package/docs/db/log.md +204 -204
- package/docs/hook/card/afterCard.md +20 -20
- package/docs/hook/card/preCard.md +25 -25
- package/docs/hook/data/afterData.md +26 -26
- package/docs/hook/data/preData.md +26 -26
- package/docs/hook/deleteCrud/afterDelete.md +21 -21
- package/docs/hook/deleteCrud/preDelete.md +26 -26
- package/docs/hook/form/afterForm.md +19 -19
- package/docs/hook/form/preForm.md +26 -26
- package/docs/hook/getTemplate/afterTemplate.md +24 -24
- package/docs/hook/getTemplate/preTemplate.md +29 -29
- package/docs/hook/index.md +45 -45
- package/docs/hook/insert/afterInsert.md +41 -41
- package/docs/hook/insert/preInsert.md +25 -25
- package/docs/hook/table/afterTable.md +20 -20
- package/docs/hook/table/preTable.md +25 -25
- package/docs/hook/update/afterUpdate.md +41 -41
- package/docs/hook/update/preUpdate.md +25 -25
- package/docs/index.md +42 -42
- package/docs/public/fastify-dark.svg +3 -3
- package/docs/public/logo-short-dark.svg +11 -11
- package/docs/public/logo-short.svg +10 -10
- package/docs/public/logo.svg +19 -19
- package/docs/readme/index.md +121 -121
- package/docs/templates/card.md +83 -83
- package/docs/templates/cls.md +29 -29
- package/docs/templates/filters.md +91 -91
- package/docs/templates/forms.md +139 -139
- package/docs/templates/index.md +28 -28
- package/docs/templates/select.md +90 -90
- package/docs/templates/table.md +162 -162
- package/docs/utils/cron/addCron.md +29 -29
- package/docs/utils/crud/dataInsert.md +51 -51
- package/docs/utils/crud/dataUpdate.md +52 -52
- package/docs/utils/crud/getOpt.md +33 -33
- package/docs/utils/crud/isFileExists.md +37 -37
- package/docs/utils/crud/setOpt.md +37 -37
- package/docs/utils/hook/addHook.md +74 -74
- package/docs/utils/hook/applyHook.md +64 -64
- package/docs/utils/index.md +47 -47
- package/docs/utils/notification/addNotification.md +28 -28
- package/docs/utils/notification/notification.md +41 -41
- package/docs/utils/pg/autoIndex.md +22 -22
- package/docs/utils/pg/getMeta.md +58 -58
- package/docs/utils/pg/getPG.md +34 -34
- package/docs/utils/pg/init.md +29 -29
- package/docs/utils/pg/pg.md +70 -70
- package/docs/utils/redis/getRedis.md +36 -36
- package/docs/utils/redis/rclient.md +74 -74
- package/docs/utils/table/getForm.md +68 -68
- package/docs/utils/table/getMeta.md +55 -55
- package/docs/utils/table/getSelect.md +38 -38
- package/docs/utils/table/getSelectMeta.md +46 -46
- package/docs/utils/table/getTable.md +77 -77
- package/helper.js +30 -30
- package/index.js +105 -105
- package/migration/exec.migrations.js +79 -79
- package/module/core/select/core.user_mentioned.sql +1 -1
- package/module/test/cls/itree.composition.json +25 -25
- package/module/test/table/test.rest_zone.table.json +265 -265
- package/notification/controllers/readNotifications.js +30 -30
- package/notification/controllers/testEmail.js +50 -50
- package/notification/controllers/userNotifications.js +64 -64
- package/notification/funcs/addNotification.js +21 -21
- package/notification/funcs/sendNotification.js +112 -112
- package/package.json +42 -41
- package/pg/funcs/getMeta.js +29 -29
- package/pg/funcs/getPG.js +30 -30
- package/pg/pgClients.js +20 -20
- package/policy/funcs/checkPolicy.js +92 -92
- package/policy/funcs/sqlInjection.js +33 -33
- package/policy/index.js +14 -14
- package/redis/client.js +8 -8
- package/redis/funcs/redisClients.js +2 -2
- package/redis/index.js +19 -19
- package/server/migrations/0.sql +78 -78
- package/server/migrations/cls.sql +39 -39
- package/server/migrations/properties.sql +144 -144
- package/server/migrations/roles.sql +172 -166
- package/server/migrations/users.sql +168 -168
- package/server.js +26 -26
- package/table/controllers/data.js +150 -134
- package/table/controllers/filter.js +50 -50
- package/table/controllers/form.js +42 -42
- package/table/controllers/search.js +80 -80
- package/table/controllers/suggest.js +79 -79
- package/table/controllers/table.js +83 -79
- package/table/controllers/utils/addTemplateDir.js +8 -8
- package/table/controllers/utils/getSelect.js +19 -19
- package/table/controllers/utils/getSelectMeta.js +66 -66
- package/table/controllers/utils/getTemplate_old.js +28 -28
- package/table/controllers/utils/getTemplates.js +18 -18
- package/table/controllers/utils/gisIRColumn.js +67 -67
- package/table/controllers/utils/loadTemplate.js +1 -1
- package/table/controllers/utils/loadTemplatePath.js +1 -1
- package/table/controllers/utils/userTemplateDir.js +1 -1
- package/table/funcs/getFilterSQL/index.js +94 -94
- package/table/funcs/getFilterSQL/util/formatValue.js +170 -170
- package/table/funcs/getFilterSQL/util/getCustomQuery.js +13 -13
- package/table/funcs/getFilterSQL/util/getFilterQuery.js +66 -66
- package/table/funcs/getFilterSQL/util/getOptimizedQuery.js +12 -12
- package/table/funcs/getFilterSQL/util/getTableSql.js +34 -34
- package/table/funcs/metaFormat/getSelectVal.js +21 -21
- package/table/funcs/metaFormat/index.js +28 -28
- package/table/index.js +37 -84
- package/table/schema.js +54 -0
- package/test/api/applyHook.test.js +95 -95
- package/test/api/crud.test.js +89 -89
- package/test/api/crud.xss.test.js +80 -80
- package/test/api/suggest.test.js +66 -66
- package/test/api/table.test.js +134 -134
- package/test/api/user.test.js +85 -85
- package/test/api/widget.test.js +117 -117
- package/test/helper/formatDate.test.js +62 -62
- package/test/templates/select/test.storage.data.json +3 -3
- package/test/templates/select/test.suggest.ato_new.json +3 -3
- package/test/templates/select/test.suggest.ato_new.sql +25 -25
- package/test/templates/select/test.suggest.data.json +4 -4
- package/test/templates/select/test.suggest.parent.sql +1 -1
- package/user/controllers/user.cls.id.js +14 -14
- package/user/controllers/user.cls.js +75 -75
- package/user/controllers/user.cls.post.js +55 -55
- package/user/controllers/user.info.js +21 -21
- package/util/controllers/logger.file.js +91 -91
- package/util/controllers/properties.add.js +60 -60
- package/util/controllers/status.monitor.js +8 -8
- package/util/controllers/utils/checkUserAccess.js +17 -17
- package/util/controllers/utils/getRootDir.js +25 -25
- package/utils.js +104 -104
- package/widget/controllers/utils/historyFormat.js +76 -76
- package/widget/controllers/utils/obj2db.js +13 -13
- package/widget/controllers/widget.del.js +44 -44
- package/widget/controllers/widget.get.js +102 -102
- package/widget/controllers/widget.set.js +79 -79
- package/widget/index.js +40 -40
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import getTemplate from '../../controllers/utils/getTemplate.js';
|
|
2
|
-
import getSelectVal from './getSelectVal.js';
|
|
3
|
-
|
|
4
|
-
export default async function metaFormat({ rows, table }) {
|
|
5
|
-
const loadTable = await getTemplate('table', table);
|
|
6
|
-
const selectCols = loadTable?.columns?.filter((e) => e.data);
|
|
7
|
-
const metaCls = Object.keys(loadTable?.meta?.cls || {}).map((el) => ({ name: el, data: loadTable?.meta?.cls[el] }));
|
|
8
|
-
if (!selectCols?.length && !metaCls?.length) return rows;
|
|
9
|
-
|
|
10
|
-
// cls & select format
|
|
11
|
-
|
|
12
|
-
await Promise.all(selectCols.concat(metaCls)?.map(async (attr) => {
|
|
13
|
-
const values = [...new Set(rows?.map((el) => el[attr.name]).flat())].filter((el) => el);
|
|
14
|
-
if (!values.length) return null;
|
|
15
|
-
|
|
16
|
-
const cls = await getSelectVal({ name: attr.data, values });
|
|
17
|
-
if (!cls) return null;
|
|
18
|
-
rows.forEach(el => {
|
|
19
|
-
const val = el[attr.name]?.map?.(c => cls[c] || c) || cls[el[attr.name]] || el[attr.name];
|
|
20
|
-
if (!val) return;
|
|
21
|
-
Object.assign(el, { [val?.color ? `${attr.name}_data` : `${attr.name}_text`]: (val.color ? val : val.text || val) });
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
return null;
|
|
25
|
-
}));
|
|
26
|
-
|
|
27
|
-
return rows;
|
|
28
|
-
}
|
|
1
|
+
import getTemplate from '../../controllers/utils/getTemplate.js';
|
|
2
|
+
import getSelectVal from './getSelectVal.js';
|
|
3
|
+
|
|
4
|
+
export default async function metaFormat({ rows, table }) {
|
|
5
|
+
const loadTable = await getTemplate('table', table);
|
|
6
|
+
const selectCols = loadTable?.columns?.filter((e) => e.data);
|
|
7
|
+
const metaCls = Object.keys(loadTable?.meta?.cls || {}).map((el) => ({ name: el, data: loadTable?.meta?.cls[el] }));
|
|
8
|
+
if (!selectCols?.length && !metaCls?.length) return rows;
|
|
9
|
+
|
|
10
|
+
// cls & select format
|
|
11
|
+
|
|
12
|
+
await Promise.all(selectCols.concat(metaCls)?.map(async (attr) => {
|
|
13
|
+
const values = [...new Set(rows?.map((el) => el[attr.name]).flat())].filter((el) => el);
|
|
14
|
+
if (!values.length) return null;
|
|
15
|
+
|
|
16
|
+
const cls = await getSelectVal({ name: attr.data, values });
|
|
17
|
+
if (!cls) return null;
|
|
18
|
+
rows.forEach(el => {
|
|
19
|
+
const val = el[attr.name]?.map?.(c => cls[c] || c) || cls[el[attr.name]] || el[attr.name];
|
|
20
|
+
if (!val) return;
|
|
21
|
+
Object.assign(el, { [val?.color ? `${attr.name}_data` : `${attr.name}_text`]: (val.color ? val : val.text || val) });
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
return null;
|
|
25
|
+
}));
|
|
26
|
+
|
|
27
|
+
return rows;
|
|
28
|
+
}
|
package/table/index.js
CHANGED
|
@@ -1,84 +1,37 @@
|
|
|
1
|
-
import suggest from './controllers/suggest.js';
|
|
2
|
-
import data from './controllers/data.js';
|
|
3
|
-
import table from './controllers/table.js';
|
|
4
|
-
import card from './controllers/card.js';
|
|
5
|
-
import search from './controllers/search.js';
|
|
6
|
-
import filter from './controllers/filter.js';
|
|
7
|
-
import form from './controllers/form.js';
|
|
8
|
-
import metaFormat from './funcs/metaFormat/index.js';
|
|
9
|
-
import getFilterSQL from './funcs/getFilterSQL/index.js';
|
|
10
|
-
import getTemplate from './controllers/utils/getTemplate.js';
|
|
11
|
-
import getSelect from './controllers/utils/getSelect.js';
|
|
12
|
-
|
|
13
|
-
import loadTemplatePath from './controllers/utils/loadTemplatePath.js';
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const suggestSchema = {
|
|
40
|
-
querystring: {
|
|
41
|
-
lang: { type: 'string', pattern: '^([\\w.]+)$' },
|
|
42
|
-
// parent: { type: 'string', pattern: '^([\\w,./]+)$' },
|
|
43
|
-
sel: { type: 'string', pattern: '^([\\w,./]+)$' },
|
|
44
|
-
name: { type: 'string', pattern: '^([\\w,./]+)$' },
|
|
45
|
-
// key: { type: 'string', pattern: '^([\\w\\d_]+)$' },
|
|
46
|
-
// val: { type: 'string', pattern: '^([\\w.,]+)$' },
|
|
47
|
-
sql: { type: 'string', pattern: '^(\\d)$' },
|
|
48
|
-
},
|
|
49
|
-
params: {
|
|
50
|
-
id: { type: 'string', pattern: '^([\\d\\w]+)$' },
|
|
51
|
-
},
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
const formSchema = {
|
|
55
|
-
params: {
|
|
56
|
-
form: { type: 'string', pattern: '^([\\w\\d_.]+)$' },
|
|
57
|
-
},
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
const filterSchema = {
|
|
61
|
-
params: {
|
|
62
|
-
table: { type: 'string', pattern: '^([\\w\\d_.]+)$' },
|
|
63
|
-
},
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
async function plugin(fastify, config = {}) {
|
|
67
|
-
const prefix = config.prefix || '/api';
|
|
68
|
-
fastify.decorate('metaFormat', metaFormat);
|
|
69
|
-
fastify.decorate('getFilterSQL', getFilterSQL);
|
|
70
|
-
fastify.decorate('getTemplate', getTemplate);
|
|
71
|
-
fastify.decorate('getSelect', getSelect);
|
|
72
|
-
|
|
73
|
-
fastify.get(`${prefix}/suggest/:data`, { schema: suggestSchema }, suggest);
|
|
74
|
-
fastify.get(`${prefix}/data/:table/:id?`, { schema: tableSchema }, data); // vs.crm.data.api с node
|
|
75
|
-
fastify.get(`${prefix}/table/:table/:id?`, { schema: tableSchema }, table);
|
|
76
|
-
fastify.get(`${prefix}/card/:table/:id`, { schema: tableSchema }, card);
|
|
77
|
-
fastify.get(`${prefix}/search`, { schema: searchSchema }, search);
|
|
78
|
-
|
|
79
|
-
fastify.get(`${prefix}/templates`, () => loadTemplatePath);
|
|
80
|
-
fastify.get(`${prefix}/filter/:table`, { schema: filterSchema }, filter);
|
|
81
|
-
fastify.get(`${prefix}/form/:form`, { schema: formSchema }, form);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export default plugin;
|
|
1
|
+
import suggest from './controllers/suggest.js';
|
|
2
|
+
import data from './controllers/data.js';
|
|
3
|
+
import table from './controllers/table.js';
|
|
4
|
+
import card from './controllers/card.js';
|
|
5
|
+
import search from './controllers/search.js';
|
|
6
|
+
import filter from './controllers/filter.js';
|
|
7
|
+
import form from './controllers/form.js';
|
|
8
|
+
import metaFormat from './funcs/metaFormat/index.js';
|
|
9
|
+
import getFilterSQL from './funcs/getFilterSQL/index.js';
|
|
10
|
+
import getTemplate from './controllers/utils/getTemplate.js';
|
|
11
|
+
import getSelect from './controllers/utils/getSelect.js';
|
|
12
|
+
|
|
13
|
+
import loadTemplatePath from './controllers/utils/loadTemplatePath.js';
|
|
14
|
+
|
|
15
|
+
import {
|
|
16
|
+
tableSchema, searchSchema, suggestSchema, formSchema, filterSchema,
|
|
17
|
+
} from './schema.js';
|
|
18
|
+
|
|
19
|
+
async function plugin(fastify, config = {}) {
|
|
20
|
+
const prefix = config.prefix || '/api';
|
|
21
|
+
fastify.decorate('metaFormat', metaFormat);
|
|
22
|
+
fastify.decorate('getFilterSQL', getFilterSQL);
|
|
23
|
+
fastify.decorate('getTemplate', getTemplate);
|
|
24
|
+
fastify.decorate('getSelect', getSelect);
|
|
25
|
+
|
|
26
|
+
fastify.get(`${prefix}/suggest/:data`, { schema: suggestSchema }, suggest);
|
|
27
|
+
fastify.get(`${prefix}/data/:table/:id?`, { schema: tableSchema }, data); // vs.crm.data.api с node
|
|
28
|
+
fastify.get(`${prefix}/table/:table/:id?`, { schema: tableSchema }, table);
|
|
29
|
+
fastify.get(`${prefix}/card/:table/:id`, { schema: tableSchema }, card);
|
|
30
|
+
fastify.get(`${prefix}/search`, { schema: searchSchema }, search);
|
|
31
|
+
|
|
32
|
+
fastify.get(`${prefix}/templates`, () => loadTemplatePath);
|
|
33
|
+
fastify.get(`${prefix}/filter/:table`, { schema: filterSchema }, filter);
|
|
34
|
+
fastify.get(`${prefix}/form/:form`, { schema: formSchema }, form);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export default plugin;
|
package/table/schema.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
const tableSchema = {
|
|
2
|
+
querystring1: {
|
|
3
|
+
page: { type: 'string', pattern: '^(\\d+)$' },
|
|
4
|
+
order: { type: 'string', pattern: '^(\\d+)$' },
|
|
5
|
+
filter: { type: 'string', pattern: '^([\\w\\d_-]+)=([\\w\\d_-]+)$' },
|
|
6
|
+
},
|
|
7
|
+
params: {
|
|
8
|
+
id: { type: 'string', pattern: '^([\\d\\w]+)$' },
|
|
9
|
+
table: { type: 'string', pattern: '^([\\w\\d_.]+)$' },
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const searchSchema = {
|
|
14
|
+
querystring: {
|
|
15
|
+
page: { type: 'string', pattern: '^(\\d+)$' },
|
|
16
|
+
limit: { type: 'string', pattern: '^(\\d+)$' },
|
|
17
|
+
order: { type: 'string', pattern: '^([\\w_.]+)$' },
|
|
18
|
+
desc: { type: 'string', pattern: '^(desc)|(asc)$' },
|
|
19
|
+
key: { type: 'string', pattern: '^([\\w\\d_]+)$' },
|
|
20
|
+
table: { type: 'string', pattern: '^([\\w\\d_.]+)$' },
|
|
21
|
+
sql: { type: 'string', pattern: '^(\\d)$' },
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const suggestSchema = {
|
|
26
|
+
querystring: {
|
|
27
|
+
lang: { type: 'string', pattern: '^([\\w.]+)$' },
|
|
28
|
+
// parent: { type: 'string', pattern: '^([\\w,./]+)$' },
|
|
29
|
+
sel: { type: 'string', pattern: '^([\\w,./]+)$' },
|
|
30
|
+
name: { type: 'string', pattern: '^([\\w,./]+)$' },
|
|
31
|
+
// key: { type: 'string', pattern: '^([\\w\\d_]+)$' },
|
|
32
|
+
// val: { type: 'string', pattern: '^([\\w.,]+)$' },
|
|
33
|
+
sql: { type: 'string', pattern: '^(\\d)$' },
|
|
34
|
+
},
|
|
35
|
+
params: {
|
|
36
|
+
id: { type: 'string', pattern: '^([\\d\\w]+)$' },
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const formSchema = {
|
|
41
|
+
params: {
|
|
42
|
+
form: { type: 'string', pattern: '^([\\w\\d_.]+)$' },
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const filterSchema = {
|
|
47
|
+
params: {
|
|
48
|
+
table: { type: 'string', pattern: '^([\\w\\d_.]+)$' },
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export {
|
|
53
|
+
tableSchema, searchSchema, suggestSchema, formSchema, filterSchema,
|
|
54
|
+
};
|
|
@@ -1,95 +1,95 @@
|
|
|
1
|
-
import { test } from 'node:test';
|
|
2
|
-
import assert from 'node:assert';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
import pgClients from '../../pg/pgClients.js';
|
|
5
|
-
import init from '../../pg/funcs/init.js';
|
|
6
|
-
|
|
7
|
-
import build from '../../helper.js';
|
|
8
|
-
import config from '../config.js';
|
|
9
|
-
|
|
10
|
-
import { addTemplateDir, addHook } from '../../utils.js';
|
|
11
|
-
|
|
12
|
-
const prefix = config.prefix || '/api';
|
|
13
|
-
const table = 'gis.dataset.table';
|
|
14
|
-
|
|
15
|
-
test('applyHook to API data/table', async (t) => {
|
|
16
|
-
const app = await build(t);
|
|
17
|
-
const cwd = process.cwd();
|
|
18
|
-
await init(pgClients.client);
|
|
19
|
-
addTemplateDir(path.join(cwd, 'test/templates'));
|
|
20
|
-
|
|
21
|
-
addHook('preData', async ({ table: table1 }) => {
|
|
22
|
-
if (table1 === `${table}1`) {
|
|
23
|
-
return { message: 'access restricted by hook', status: 403 };
|
|
24
|
-
}
|
|
25
|
-
return null;
|
|
26
|
-
});
|
|
27
|
-
addHook('preTable', async ({ table: table1 }) => {
|
|
28
|
-
if (table1 === `${table}1`) {
|
|
29
|
-
return { message: 'access restricted by hook', status: 403 };
|
|
30
|
-
}
|
|
31
|
-
return null;
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
addHook('afterData', async ({ res }) => {
|
|
35
|
-
Object.assign(res, { test: '1' });
|
|
36
|
-
});
|
|
37
|
-
addHook('afterTable', async ({ rows = [] }) => {
|
|
38
|
-
Object.assign(rows[0], { count: 1 });
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
await t.test('GET /data (preData ok)', async () => {
|
|
42
|
-
const res = await app.inject({
|
|
43
|
-
method: 'GET',
|
|
44
|
-
url: `${prefix}/data/${table}`,
|
|
45
|
-
});
|
|
46
|
-
const json = res.json();
|
|
47
|
-
assert.ok(json?.time, 'api error');
|
|
48
|
-
});
|
|
49
|
-
await t.test('GET /data (preData message)', async () => {
|
|
50
|
-
const res = await app.inject({
|
|
51
|
-
method: 'GET',
|
|
52
|
-
url: `${prefix}/data/${table}1`,
|
|
53
|
-
});
|
|
54
|
-
const json = res.json();
|
|
55
|
-
assert.ok(json.message === 'access restricted by hook', 'preData hook error');
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
await t.test('GET /data (afterData)', async () => {
|
|
59
|
-
const res = await app.inject({
|
|
60
|
-
method: 'GET',
|
|
61
|
-
url: `${prefix}/data/${table}`,
|
|
62
|
-
});
|
|
63
|
-
const json = res.json();
|
|
64
|
-
assert.ok(json?.test === '1', 'afterData hook error');
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
const { id = '1' } = pgClients.client?.pk['gis.dataset']
|
|
68
|
-
? await pgClients.client.query('select dataset_id as id from gis.dataset limit 1')
|
|
69
|
-
.then((res) => res.rows?.[0] || {}) : {};
|
|
70
|
-
await t.test('GET /table/:id (preTable ok)', async () => {
|
|
71
|
-
const res = await app.inject({
|
|
72
|
-
method: 'GET',
|
|
73
|
-
url: `${prefix}/table/${table}1/${id}`,
|
|
74
|
-
});
|
|
75
|
-
const json = res.json();
|
|
76
|
-
assert.ok(json.message === 'access restricted by hook', 'preTable hook error');
|
|
77
|
-
});
|
|
78
|
-
await t.test('GET /table/:id (preTable message)', async () => {
|
|
79
|
-
const res = await app.inject({
|
|
80
|
-
method: 'GET',
|
|
81
|
-
url: `${prefix}/table/${table}1/${id}`,
|
|
82
|
-
});
|
|
83
|
-
const json = res.json();
|
|
84
|
-
assert.ok(json.message === 'access restricted by hook', 'preTable hook error');
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
await t.test('GET /table/:id (afterTable)', async () => {
|
|
88
|
-
const res = await app.inject({
|
|
89
|
-
method: 'GET',
|
|
90
|
-
url: `${prefix}/table/${table}/${id}`,
|
|
91
|
-
});
|
|
92
|
-
const json = res.json();
|
|
93
|
-
assert.equal(json?.count, 1);
|
|
94
|
-
});
|
|
95
|
-
});
|
|
1
|
+
import { test } from 'node:test';
|
|
2
|
+
import assert from 'node:assert';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import pgClients from '../../pg/pgClients.js';
|
|
5
|
+
import init from '../../pg/funcs/init.js';
|
|
6
|
+
|
|
7
|
+
import build from '../../helper.js';
|
|
8
|
+
import config from '../config.js';
|
|
9
|
+
|
|
10
|
+
import { addTemplateDir, addHook } from '../../utils.js';
|
|
11
|
+
|
|
12
|
+
const prefix = config.prefix || '/api';
|
|
13
|
+
const table = 'gis.dataset.table';
|
|
14
|
+
|
|
15
|
+
test('applyHook to API data/table', async (t) => {
|
|
16
|
+
const app = await build(t);
|
|
17
|
+
const cwd = process.cwd();
|
|
18
|
+
await init(pgClients.client);
|
|
19
|
+
addTemplateDir(path.join(cwd, 'test/templates'));
|
|
20
|
+
|
|
21
|
+
addHook('preData', async ({ table: table1 }) => {
|
|
22
|
+
if (table1 === `${table}1`) {
|
|
23
|
+
return { message: 'access restricted by hook', status: 403 };
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
});
|
|
27
|
+
addHook('preTable', async ({ table: table1 }) => {
|
|
28
|
+
if (table1 === `${table}1`) {
|
|
29
|
+
return { message: 'access restricted by hook', status: 403 };
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
addHook('afterData', async ({ res }) => {
|
|
35
|
+
Object.assign(res, { test: '1' });
|
|
36
|
+
});
|
|
37
|
+
addHook('afterTable', async ({ rows = [] }) => {
|
|
38
|
+
Object.assign(rows[0], { count: 1 });
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
await t.test('GET /data (preData ok)', async () => {
|
|
42
|
+
const res = await app.inject({
|
|
43
|
+
method: 'GET',
|
|
44
|
+
url: `${prefix}/data/${table}`,
|
|
45
|
+
});
|
|
46
|
+
const json = res.json();
|
|
47
|
+
assert.ok(json?.time, 'api error');
|
|
48
|
+
});
|
|
49
|
+
await t.test('GET /data (preData message)', async () => {
|
|
50
|
+
const res = await app.inject({
|
|
51
|
+
method: 'GET',
|
|
52
|
+
url: `${prefix}/data/${table}1`,
|
|
53
|
+
});
|
|
54
|
+
const json = res.json();
|
|
55
|
+
assert.ok(json.message === 'access restricted by hook', 'preData hook error');
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
await t.test('GET /data (afterData)', async () => {
|
|
59
|
+
const res = await app.inject({
|
|
60
|
+
method: 'GET',
|
|
61
|
+
url: `${prefix}/data/${table}`,
|
|
62
|
+
});
|
|
63
|
+
const json = res.json();
|
|
64
|
+
assert.ok(json?.test === '1', 'afterData hook error');
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const { id = '1' } = pgClients.client?.pk['gis.dataset']
|
|
68
|
+
? await pgClients.client.query('select dataset_id as id from gis.dataset limit 1')
|
|
69
|
+
.then((res) => res.rows?.[0] || {}) : {};
|
|
70
|
+
await t.test('GET /table/:id (preTable ok)', async () => {
|
|
71
|
+
const res = await app.inject({
|
|
72
|
+
method: 'GET',
|
|
73
|
+
url: `${prefix}/table/${table}1/${id}`,
|
|
74
|
+
});
|
|
75
|
+
const json = res.json();
|
|
76
|
+
assert.ok(json.message === 'access restricted by hook', 'preTable hook error');
|
|
77
|
+
});
|
|
78
|
+
await t.test('GET /table/:id (preTable message)', async () => {
|
|
79
|
+
const res = await app.inject({
|
|
80
|
+
method: 'GET',
|
|
81
|
+
url: `${prefix}/table/${table}1/${id}`,
|
|
82
|
+
});
|
|
83
|
+
const json = res.json();
|
|
84
|
+
assert.ok(json.message === 'access restricted by hook', 'preTable hook error');
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
await t.test('GET /table/:id (afterTable)', async () => {
|
|
88
|
+
const res = await app.inject({
|
|
89
|
+
method: 'GET',
|
|
90
|
+
url: `${prefix}/table/${table}/${id}`,
|
|
91
|
+
});
|
|
92
|
+
const json = res.json();
|
|
93
|
+
assert.equal(json?.count, 1);
|
|
94
|
+
});
|
|
95
|
+
});
|
package/test/api/crud.test.js
CHANGED
|
@@ -1,89 +1,89 @@
|
|
|
1
|
-
import { test } from 'node:test';
|
|
2
|
-
import assert from 'node:assert';
|
|
3
|
-
|
|
4
|
-
import build from '../../helper.js';
|
|
5
|
-
|
|
6
|
-
import config from '../config.js';
|
|
7
|
-
import pgClients from '../../pg/pgClients.js';
|
|
8
|
-
|
|
9
|
-
const mapId = '5400000';
|
|
10
|
-
|
|
11
|
-
test('api crud', async (t) => {
|
|
12
|
-
const app = await build(t);
|
|
13
|
-
assert.ok(111);
|
|
14
|
-
return;
|
|
15
|
-
const prefix = config.prefix || '/api';
|
|
16
|
-
|
|
17
|
-
// delete old test data before test
|
|
18
|
-
const { rowCount } = await pgClients.client.query('delete from gis.map where map_id=$1', [mapId]);
|
|
19
|
-
console.log(rowCount);
|
|
20
|
-
|
|
21
|
-
app.addHook('onRequest', async (req) => {
|
|
22
|
-
req.session = { passport: { user: { uid: '1' } } };
|
|
23
|
-
req.user = req.session.passport.user;
|
|
24
|
-
req.uid = req.user.uid;
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
await t.test('POST /insert', async () => {
|
|
28
|
-
const res = await app.inject({
|
|
29
|
-
method: 'POST',
|
|
30
|
-
url: `${prefix}/table/test.gis.map.table`,
|
|
31
|
-
body: {
|
|
32
|
-
alias: 'testMap',
|
|
33
|
-
map_id: mapId,
|
|
34
|
-
ord: 1,
|
|
35
|
-
enabled: false,
|
|
36
|
-
tags: ['unit', 'test'],
|
|
37
|
-
},
|
|
38
|
-
});
|
|
39
|
-
assert.ok(res.json().rows ? res.json().rows[0]?.map_id : res.json().map_id, res.json().status);
|
|
40
|
-
assert.ok(111);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
await t.test('POST /properties/:id', async () => {
|
|
44
|
-
const res = await app.inject({
|
|
45
|
-
method: 'POST',
|
|
46
|
-
url: `${prefix}/properties/${mapId}`,
|
|
47
|
-
body: {
|
|
48
|
-
custom_alias: 'testMap',
|
|
49
|
-
custom_ord: 5,
|
|
50
|
-
},
|
|
51
|
-
});
|
|
52
|
-
assert.ok(res.json().message?.rows?.length, res.json().status);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
await t.test('GET /properties/:id', async () => {
|
|
56
|
-
const res = await app.inject({
|
|
57
|
-
method: 'GET',
|
|
58
|
-
url: `${prefix}/properties/${mapId}`,
|
|
59
|
-
});
|
|
60
|
-
assert.ok(res.json().message?.custom_alias, res.json().status);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
await t.test('PUT /update', async () => {
|
|
64
|
-
const res = await app.inject({
|
|
65
|
-
method: 'PUT',
|
|
66
|
-
url: `${prefix}/table/test.gis.map.table/${mapId}`,
|
|
67
|
-
body: {
|
|
68
|
-
editor_id: '11',
|
|
69
|
-
alias: 'testMapEdit',
|
|
70
|
-
map_id: mapId,
|
|
71
|
-
ord: 2,
|
|
72
|
-
enabled: true,
|
|
73
|
-
tags: ['unittest'],
|
|
74
|
-
},
|
|
75
|
-
});
|
|
76
|
-
// console.log(res);
|
|
77
|
-
assert.ok((res.json().rows ? res.json().rows[0]?.editor_id : res.json().editor_id) === '11', res.json().status);
|
|
78
|
-
assert.ok(11);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
await t.test('DELETE /delete', async () => {
|
|
82
|
-
const res = await app.inject({
|
|
83
|
-
method: 'DELETE',
|
|
84
|
-
url: `${prefix}/table/test.gis.map.table/${mapId}`,
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
assert.ok(res.json().msg?.map_id === mapId, res.json().status);
|
|
88
|
-
});
|
|
89
|
-
});
|
|
1
|
+
import { test } from 'node:test';
|
|
2
|
+
import assert from 'node:assert';
|
|
3
|
+
|
|
4
|
+
import build from '../../helper.js';
|
|
5
|
+
|
|
6
|
+
import config from '../config.js';
|
|
7
|
+
import pgClients from '../../pg/pgClients.js';
|
|
8
|
+
|
|
9
|
+
const mapId = '5400000';
|
|
10
|
+
|
|
11
|
+
test('api crud', async (t) => {
|
|
12
|
+
const app = await build(t);
|
|
13
|
+
assert.ok(111);
|
|
14
|
+
return;
|
|
15
|
+
const prefix = config.prefix || '/api';
|
|
16
|
+
|
|
17
|
+
// delete old test data before test
|
|
18
|
+
const { rowCount } = await pgClients.client.query('delete from gis.map where map_id=$1', [mapId]);
|
|
19
|
+
console.log(rowCount);
|
|
20
|
+
|
|
21
|
+
app.addHook('onRequest', async (req) => {
|
|
22
|
+
req.session = { passport: { user: { uid: '1' } } };
|
|
23
|
+
req.user = req.session.passport.user;
|
|
24
|
+
req.uid = req.user.uid;
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
await t.test('POST /insert', async () => {
|
|
28
|
+
const res = await app.inject({
|
|
29
|
+
method: 'POST',
|
|
30
|
+
url: `${prefix}/table/test.gis.map.table`,
|
|
31
|
+
body: {
|
|
32
|
+
alias: 'testMap',
|
|
33
|
+
map_id: mapId,
|
|
34
|
+
ord: 1,
|
|
35
|
+
enabled: false,
|
|
36
|
+
tags: ['unit', 'test'],
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
assert.ok(res.json().rows ? res.json().rows[0]?.map_id : res.json().map_id, res.json().status);
|
|
40
|
+
assert.ok(111);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
await t.test('POST /properties/:id', async () => {
|
|
44
|
+
const res = await app.inject({
|
|
45
|
+
method: 'POST',
|
|
46
|
+
url: `${prefix}/properties/${mapId}`,
|
|
47
|
+
body: {
|
|
48
|
+
custom_alias: 'testMap',
|
|
49
|
+
custom_ord: 5,
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
assert.ok(res.json().message?.rows?.length, res.json().status);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
await t.test('GET /properties/:id', async () => {
|
|
56
|
+
const res = await app.inject({
|
|
57
|
+
method: 'GET',
|
|
58
|
+
url: `${prefix}/properties/${mapId}`,
|
|
59
|
+
});
|
|
60
|
+
assert.ok(res.json().message?.custom_alias, res.json().status);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
await t.test('PUT /update', async () => {
|
|
64
|
+
const res = await app.inject({
|
|
65
|
+
method: 'PUT',
|
|
66
|
+
url: `${prefix}/table/test.gis.map.table/${mapId}`,
|
|
67
|
+
body: {
|
|
68
|
+
editor_id: '11',
|
|
69
|
+
alias: 'testMapEdit',
|
|
70
|
+
map_id: mapId,
|
|
71
|
+
ord: 2,
|
|
72
|
+
enabled: true,
|
|
73
|
+
tags: ['unittest'],
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
// console.log(res);
|
|
77
|
+
assert.ok((res.json().rows ? res.json().rows[0]?.editor_id : res.json().editor_id) === '11', res.json().status);
|
|
78
|
+
assert.ok(11);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
await t.test('DELETE /delete', async () => {
|
|
82
|
+
const res = await app.inject({
|
|
83
|
+
method: 'DELETE',
|
|
84
|
+
url: `${prefix}/table/test.gis.map.table/${mapId}`,
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
assert.ok(res.json().msg?.map_id === mapId, res.json().status);
|
|
88
|
+
});
|
|
89
|
+
});
|