@opengis/fastify-table 1.1.81 → 1.1.83
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/README.md
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
# fastify-table
|
|
2
|
-
|
|
3
|
-
[](https://www.npmjs.com/package/@opengis/fastify-table)
|
|
4
|
-
[](http://standardjs.com/)
|
|
5
|
-
|
|
6
|
-
It standardizes the entire form building process, while taking care of everything from rendering to validation and processing:
|
|
7
|
-
|
|
8
|
-
- pg
|
|
9
|
-
- redis
|
|
10
|
-
- crud
|
|
11
|
-
|
|
12
|
-
## Install
|
|
13
|
-
|
|
14
|
-
```bash
|
|
15
|
-
npm i @opengis/fastify-table
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
## Usage
|
|
19
|
-
|
|
20
|
-
```js
|
|
21
|
-
fastify.register(import('@opengis/fastify-table'), config);
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
## Documenation
|
|
25
|
-
|
|
26
|
-
For a detailed understanding fastify-table, its features, and how to use them, refer to our [Documentation](https://apidocs.softpro.ua/gis.storage/).
|
|
1
|
+
# fastify-table
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@opengis/fastify-table)
|
|
4
|
+
[](http://standardjs.com/)
|
|
5
|
+
|
|
6
|
+
It standardizes the entire form building process, while taking care of everything from rendering to validation and processing:
|
|
7
|
+
|
|
8
|
+
- pg
|
|
9
|
+
- redis
|
|
10
|
+
- crud
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm i @opengis/fastify-table
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
```js
|
|
21
|
+
fastify.register(import('@opengis/fastify-table'), config);
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Documenation
|
|
25
|
+
|
|
26
|
+
For a detailed understanding fastify-table, its features, and how to use them, refer to our [Documentation](https://apidocs.softpro.ua/gis.storage/).
|
package/config.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
|
|
3
|
-
const fileName = ['config.json', '/data/local/config.json'].find(el => (fs.existsSync(el) ? el : null));
|
|
4
|
-
const config = fileName ? JSON.parse(fs.readFileSync(fileName)) : {};
|
|
5
|
-
|
|
6
|
-
Object.assign(config, {
|
|
7
|
-
allTemplates: config?.allTemplates || {},
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
export default config;
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
|
|
3
|
+
const fileName = ['config.json', '/data/local/config.json'].find(el => (fs.existsSync(el) ? el : null));
|
|
4
|
+
const config = fileName ? JSON.parse(fs.readFileSync(fileName)) : {};
|
|
5
|
+
|
|
6
|
+
Object.assign(config, {
|
|
7
|
+
allTemplates: config?.allTemplates || {},
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
export default config;
|
package/package.json
CHANGED
|
@@ -133,16 +133,16 @@ function formatValue({
|
|
|
133
133
|
|
|
134
134
|
if (['~', '='].includes(operator)) {
|
|
135
135
|
const operator1 = (filterType === 'text' && (filter?.id || filter?.name) && operator === '=' ? '~' : operator);
|
|
136
|
-
const match = operator1 === '=' ? `='${value}'` : `ilike '%${value}%'`;
|
|
136
|
+
const match = (operator1 === '=' || filterType === 'autocomplete') ? `='${value}'` : `ilike '%${value}%'`;
|
|
137
137
|
if (extra && pk) {
|
|
138
138
|
const query = data && sql
|
|
139
|
-
? `${pk} in (select object_id from crm.extra_data where property_key='${name}' and value_text in ( ( with q(id,name) as (${sql}) select id from q where name ${match})))`
|
|
139
|
+
? `${pk} in (select object_id from crm.extra_data where property_key='${name}' and value_text in ( ( with q(id,name) as (${sql}) select id from q where ${filterType === 'autocomplete' ? 'id' : 'name'} ${match})))`
|
|
140
140
|
: `${pk} in (select object_id from crm.extra_data where property_key='${name}' and value_text ${match})`;
|
|
141
141
|
return { op: 'ilike', query, extra };
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
const query = filter?.data && filter?.sql
|
|
145
|
-
? `${filter?.name || filter?.id} in ( ( with q(id,name) as (${filter?.sql}) select id from q where name::text ${match}) )` // filter with cls
|
|
145
|
+
? `${filter?.name || filter?.id} in ( ( with q(id,name) as (${filter?.sql}) select id from q where ${filterType === 'autocomplete' ? 'id' : 'name'}::text ${match}) )` // filter with cls
|
|
146
146
|
: `${name}::text ${match}`; // simple filter
|
|
147
147
|
// console.log(query);
|
|
148
148
|
return { op: 'ilike', query };
|
|
@@ -46,7 +46,8 @@ export default async function getSelectMeta({ name, pg = pgClients.client, nocac
|
|
|
46
46
|
const searchQuery = `(${searchColumn.split(',').map((el) => `lower("${el}") ~ $1 `).join(' or ')})`;
|
|
47
47
|
// console.log(dataOrigin1.fields.map((el) => el.name).join(','));
|
|
48
48
|
const data = {
|
|
49
|
-
|
|
49
|
+
minLength: cls.minLength,
|
|
50
|
+
limit: cls.limit,
|
|
50
51
|
type: type.join(','),
|
|
51
52
|
cols: cols.join(','),
|
|
52
53
|
originalCols: originalCols.join(','),
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
config, getPG, getTemplate, getSelectMeta,
|
|
3
3
|
} from '../../../../utils.js';
|
|
4
4
|
|
|
5
|
-
const limit =
|
|
5
|
+
const limit = 20;
|
|
6
6
|
const headers = {
|
|
7
7
|
'Access-Control-Allow-Origin': '*',
|
|
8
8
|
'Access-Control-Allow-Methods': 'GET',
|
|
@@ -37,6 +37,9 @@ export default async function suggest(req) {
|
|
|
37
37
|
searchQuery: '(lower("text") ~ $1 )',
|
|
38
38
|
}
|
|
39
39
|
: await getSelectMeta({ name: selectName, nocache: query?.nocache });
|
|
40
|
+
if (meta.minLength && query.key && query.key.length < meta.minLength) {
|
|
41
|
+
return { message: `min length: ${meta.minLength}` };
|
|
42
|
+
}
|
|
40
43
|
const pg = meta?.db ? getPG(meta.db) : pg1;
|
|
41
44
|
if (!meta) return { headers, status: 404, message: 'Not found query select ' };
|
|
42
45
|
if (query.meta) return meta;
|
|
@@ -62,7 +65,7 @@ export default async function suggest(req) {
|
|
|
62
65
|
|
|
63
66
|
const val = query.val ? ` ${meta.pk}=any('{${query.val.replace(/'/g, "''")}}')` : '';
|
|
64
67
|
const where = [search, val, `${meta.pk} is not null`].filter((el) => el).join(' and ') || 'true';
|
|
65
|
-
const sqlSuggest = `with c(id,text) as ( ${meta.original.replace(/{{parent}}/gi, parent)} where ${where} order by 2) select * from c `.replace(/{{uid}}/g, user?.uid || '0');
|
|
68
|
+
const sqlSuggest = `with c(id,text) as ( ${meta.original.replace(/{{parent}}/gi, parent)} where ${where} order by 2) select * from c limit ${meta.limit || 20}`.replace(/{{uid}}/g, user?.uid || '0');
|
|
66
69
|
if (query.sql && config.local) return sqlSuggest;
|
|
67
70
|
|
|
68
71
|
// query
|