@opengis/fastify-table 1.1.118 → 1.1.119
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
|
@@ -21,17 +21,21 @@ export default async function suggest(req) {
|
|
|
21
21
|
const [table, column] = params.data?.includes(':') ? params.data.split(':') : [];
|
|
22
22
|
const selectName = query.sel || query.name || params.data;
|
|
23
23
|
|
|
24
|
-
if (!selectName) return {
|
|
24
|
+
if (!selectName) return { status: 400, message: 'name is required' };
|
|
25
25
|
|
|
26
26
|
const body = await getTemplate('table', table);
|
|
27
27
|
|
|
28
28
|
if (table && !pg1.pk[body?.table || table]) {
|
|
29
|
-
return {
|
|
29
|
+
return { status: 400, message: 'param name is invalid: 1' };
|
|
30
30
|
}
|
|
31
31
|
const columnExists = body?.columns?.find((col) => col?.name === column);
|
|
32
32
|
|
|
33
33
|
if (table && (!column || !columnExists)) {
|
|
34
|
-
return {
|
|
34
|
+
return { status: 400, message: 'param name is invalid: 2' };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (query.limit && query.limit < 0) {
|
|
38
|
+
return { status: 400, message: 'param limit is invalid' };
|
|
35
39
|
}
|
|
36
40
|
|
|
37
41
|
const meta = table && column
|
|
@@ -59,11 +63,17 @@ export default async function suggest(req) {
|
|
|
59
63
|
|
|
60
64
|
if (arr) {
|
|
61
65
|
const lower = query.key?.toLowerCase();
|
|
62
|
-
const
|
|
66
|
+
const data1 = query.key || query.val
|
|
63
67
|
? arr?.filter((el) => !lower || (el[lang] || el.text)?.toLowerCase()?.indexOf(lower) !== -1)?.filter((el) => !query.val || el.id === query.val)
|
|
64
68
|
: arr;
|
|
69
|
+
const data = data1.slice(0, Math.min(query.limit || limit, limit));
|
|
65
70
|
return {
|
|
66
|
-
|
|
71
|
+
time: Date.now() - time,
|
|
72
|
+
limit: Math.min(query.limit || limit, limit),
|
|
73
|
+
count: data.length,
|
|
74
|
+
total: arr.length,
|
|
75
|
+
mode: 'array',
|
|
76
|
+
data,
|
|
67
77
|
};
|
|
68
78
|
}
|
|
69
79
|
|
|
@@ -85,7 +95,7 @@ export default async function suggest(req) {
|
|
|
85
95
|
? `id in (select ${filterColumn} from ${(loadTable?.table || query.token).replace(/'/g, "''")})`
|
|
86
96
|
: 'true';
|
|
87
97
|
|
|
88
|
-
const sqlSuggest = `with c(id,text) as ( ${meta.original.replace(/{{parent}}/gi, parent)} where ${where} order by 2) select * from c where ${filter} limit ${meta.limit || limit}`.replace(/{{uid}}/g, user?.uid || '0');
|
|
98
|
+
const sqlSuggest = `with c(id,text) as ( ${meta.original.replace(/{{parent}}/gi, parent)} where ${where} order by 2) select * from c where ${filter} limit ${Math.min(query.limit || meta.limit || limit, limit)}`.replace(/{{uid}}/g, user?.uid || '0');
|
|
89
99
|
|
|
90
100
|
if (query.sql && config.local) {
|
|
91
101
|
return sqlSuggest;
|
|
@@ -99,6 +109,7 @@ export default async function suggest(req) {
|
|
|
99
109
|
|
|
100
110
|
const message = {
|
|
101
111
|
time: Date.now() - time,
|
|
112
|
+
limit: Math.min(query.limit || meta.limit || limit, limit),
|
|
102
113
|
count: data.length,
|
|
103
114
|
total: meta.count - 0,
|
|
104
115
|
mode: 'sql',
|