@opengis/fastify-table 1.0.3 → 1.0.5
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/README.md +26 -26
- package/{Changelog.md → changelog.md} +26 -20
- package/config.js +3 -3
- package/crud/controllers/deleteCrud.js +10 -10
- package/crud/controllers/insert.js +9 -9
- package/crud/controllers/update.js +10 -10
- package/crud/funcs/dataDelete.js +15 -0
- package/crud/funcs/dataInsert.js +24 -24
- package/crud/funcs/dataUpdate.js +20 -20
- package/crud/funcs/isFileExists.js +13 -13
- package/crud/index.js +29 -29
- package/helper.js +28 -28
- package/index.js +22 -22
- package/package.json +22 -22
- package/pg/funcs/autoIndex.js +89 -89
- package/pg/funcs/getMeta.js +27 -27
- package/pg/funcs/init.js +42 -42
- package/pg/funcs/pgClients.js +2 -2
- package/pg/index.js +35 -35
- package/pg/pgClients.js +17 -17
- package/redis/client.js +8 -8
- package/redis/funcs/redisClients.js +2 -2
- package/redis/index.js +19 -18
- package/server.js +14 -0
- package/table/controllers/data.js +51 -48
- package/table/controllers/filter.js +17 -17
- package/table/controllers/form.js +10 -10
- package/table/controllers/suggest.js +59 -56
- package/table/controllers/utils/getSelect.js +20 -20
- package/table/controllers/utils/getSelectMeta.js +66 -65
- package/table/controllers/utils/getTemplate.js +24 -24
- package/table/funcs/getFilterSQL/index.js +75 -75
- package/table/funcs/getFilterSQL/util/formatValue.js +142 -142
- package/table/funcs/getFilterSQL/util/getCustomQuery.js +13 -13
- package/table/funcs/getFilterSQL/util/getFilterQuery.js +73 -73
- package/table/funcs/getFilterSQL/util/getOptimizedQuery.js +12 -12
- package/table/funcs/getFilterSQL/util/getTableSql.js +34 -34
- package/table/index.js +14 -14
- package/test/api/crud.test.js +23 -23
- package/test/api/table.test.js +29 -29
- package/test/config.example +18 -18
- package/test/funcs/crud.test.js +37 -37
- package/test/funcs/pg.test.js +26 -26
- package/test/funcs/redis.test.js +19 -19
- package/test/funcs/table.test.js +19 -19
- package/test/templates/cls/test.json +9 -9
- package/test/templates/form/cp_building.form.json +32 -32
- package/test/templates/select/account_id.json +4 -0
- package/test/templates/select/account_id.sql +1 -0
- package/test/templates/select/atu.nsdi.ato_level.json +4 -0
- package/test/templates/select/atu.nsdi.ato_level.sql +11 -0
- package/test/templates/select/storage.data.json +2 -2
- package/test/templates/table/gis.dataset.table.json +20 -42
- package/test/templates/table/service.json +18 -0
package/.eslintrc.cjs
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
/* eslint-env node */
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
4
|
-
env: {
|
|
5
|
-
node: true,
|
|
6
|
-
},
|
|
7
|
-
root: true,
|
|
8
|
-
extends: [
|
|
9
|
-
'eslint:recommended',
|
|
10
|
-
'airbnb-base',
|
|
11
|
-
|
|
12
|
-
],
|
|
13
|
-
rules: {
|
|
14
|
-
'brace-style': [2, 'stroustrup', { allowSingleLine: true }],
|
|
15
|
-
'vue/max-attributes-per-line': 0,
|
|
16
|
-
'vue/valid-v-for': 0,
|
|
17
|
-
|
|
18
|
-
// allow async-await
|
|
19
|
-
'generator-star-spacing': 'off',
|
|
20
|
-
|
|
21
|
-
// allow paren-less arrow functions
|
|
22
|
-
'arrow-parens': 0,
|
|
23
|
-
'one-var': 0,
|
|
24
|
-
'max-len': 0,
|
|
25
|
-
'import/first': 0,
|
|
26
|
-
'import/named': 2,
|
|
27
|
-
'import/namespace': 2,
|
|
28
|
-
'import/default': 2,
|
|
29
|
-
'import/export': 2,
|
|
30
|
-
'import/extensions': 0,
|
|
31
|
-
'no-console': ['warn', { allow: ['warn', 'error'] }],
|
|
32
|
-
'import/no-unresolved': 0,
|
|
33
|
-
'import/no-extraneous-dependencies': 0,
|
|
34
|
-
'linebreak-style': ['error', 'unix'],
|
|
35
|
-
// allow debugger during development
|
|
36
|
-
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
|
|
37
|
-
},
|
|
38
|
-
|
|
39
|
-
parserOptions: {
|
|
40
|
-
ecmaVersion: 'latest',
|
|
41
|
-
},
|
|
42
|
-
};
|
|
1
|
+
/* eslint-env node */
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
env: {
|
|
5
|
+
node: true,
|
|
6
|
+
},
|
|
7
|
+
root: true,
|
|
8
|
+
extends: [
|
|
9
|
+
'eslint:recommended',
|
|
10
|
+
'airbnb-base',
|
|
11
|
+
|
|
12
|
+
],
|
|
13
|
+
rules: {
|
|
14
|
+
'brace-style': [2, 'stroustrup', { allowSingleLine: true }],
|
|
15
|
+
'vue/max-attributes-per-line': 0,
|
|
16
|
+
'vue/valid-v-for': 0,
|
|
17
|
+
|
|
18
|
+
// allow async-await
|
|
19
|
+
'generator-star-spacing': 'off',
|
|
20
|
+
|
|
21
|
+
// allow paren-less arrow functions
|
|
22
|
+
'arrow-parens': 0,
|
|
23
|
+
'one-var': 0,
|
|
24
|
+
'max-len': 0,
|
|
25
|
+
'import/first': 0,
|
|
26
|
+
'import/named': 2,
|
|
27
|
+
'import/namespace': 2,
|
|
28
|
+
'import/default': 2,
|
|
29
|
+
'import/export': 2,
|
|
30
|
+
'import/extensions': 0,
|
|
31
|
+
'no-console': ['warn', { allow: ['warn', 'error'] }],
|
|
32
|
+
'import/no-unresolved': 0,
|
|
33
|
+
'import/no-extraneous-dependencies': 0,
|
|
34
|
+
'linebreak-style': ['error', 'unix'],
|
|
35
|
+
// allow debugger during development
|
|
36
|
+
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
parserOptions: {
|
|
40
|
+
ecmaVersion: 'latest',
|
|
41
|
+
},
|
|
42
|
+
};
|
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/).
|
|
@@ -1,20 +1,26 @@
|
|
|
1
|
-
# fastify-table
|
|
2
|
-
|
|
3
|
-
## 1.0.
|
|
4
|
-
|
|
5
|
-
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
-
|
|
18
|
-
|
|
19
|
-
- redis
|
|
20
|
-
|
|
1
|
+
# fastify-table
|
|
2
|
+
|
|
3
|
+
## 1.0.4 - 20.04.2024
|
|
4
|
+
|
|
5
|
+
- data api - order
|
|
6
|
+
- suggest api - db support
|
|
7
|
+
- del api fix
|
|
8
|
+
|
|
9
|
+
## 1.0.3 - 17.04.2024
|
|
10
|
+
|
|
11
|
+
- fix unit test
|
|
12
|
+
|
|
13
|
+
## 1.0.2 - 14.04.2024
|
|
14
|
+
|
|
15
|
+
- fix redis
|
|
16
|
+
|
|
17
|
+
## 1.0.1 - 14.04.2024
|
|
18
|
+
|
|
19
|
+
- fix redis
|
|
20
|
+
|
|
21
|
+
## 1.0.0 - 14.04.2024
|
|
22
|
+
|
|
23
|
+
- crud
|
|
24
|
+
- pg
|
|
25
|
+
- redis
|
|
26
|
+
- table
|
package/config.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
// import pg from './pg'
|
|
2
|
-
const config = { allTemplates: {} };
|
|
3
|
-
export default config;
|
|
1
|
+
// import pg from './pg'
|
|
2
|
+
const config = { allTemplates: {} };
|
|
3
|
+
export default config;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const data = await
|
|
8
|
-
|
|
9
|
-
return { rowCount: data.rowCount };
|
|
10
|
-
}
|
|
1
|
+
import dataDelete from '../funcs/dataDelete.js';
|
|
2
|
+
|
|
3
|
+
export default async function deleteCrud(req) {
|
|
4
|
+
const { table, id } = req.params || {};
|
|
5
|
+
if (!table) return { status: 404, message: 'table is required' };
|
|
6
|
+
|
|
7
|
+
const data = await dataDelete({ table, id });
|
|
8
|
+
|
|
9
|
+
return { rowCount: data.rowCount, msg: !data.rowCount ? data : null };
|
|
10
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import dataInsert from '../funcs/dataInsert.js';
|
|
2
|
-
|
|
3
|
-
export default async function insert(req) {
|
|
4
|
-
const { table } = req.params || {};
|
|
5
|
-
if (!table) return { status: 404, message: 'table is required' };
|
|
6
|
-
|
|
7
|
-
const res = await dataInsert({ table, data: req.body });
|
|
8
|
-
return res;
|
|
9
|
-
}
|
|
1
|
+
import dataInsert from '../funcs/dataInsert.js';
|
|
2
|
+
|
|
3
|
+
export default async function insert(req) {
|
|
4
|
+
const { table } = req.params || {};
|
|
5
|
+
if (!table) return { status: 404, message: 'table is required' };
|
|
6
|
+
|
|
7
|
+
const res = await dataInsert({ table, data: req.body });
|
|
8
|
+
return res;
|
|
9
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import dataUpdate from '../funcs/dataUpdate.js';
|
|
2
|
-
|
|
3
|
-
export default async function update(req) {
|
|
4
|
-
const { table, id } = req.params || {};
|
|
5
|
-
if (!table) return { status: 404, message: 'table is required' };
|
|
6
|
-
if (!id) return { status: 404, message: 'id is required' };
|
|
7
|
-
|
|
8
|
-
const res = await dataUpdate({ table, id, data: req.body });
|
|
9
|
-
return res;
|
|
10
|
-
}
|
|
1
|
+
import dataUpdate from '../funcs/dataUpdate.js';
|
|
2
|
+
|
|
3
|
+
export default async function update(req) {
|
|
4
|
+
const { table, id } = req.params || {};
|
|
5
|
+
if (!table) return { status: 404, message: 'table is required' };
|
|
6
|
+
if (!id) return { status: 404, message: 'id is required' };
|
|
7
|
+
|
|
8
|
+
const res = await dataUpdate({ table, id, data: req.body });
|
|
9
|
+
return res;
|
|
10
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import getPG from '../../pg/funcs/getPG.js';
|
|
2
|
+
|
|
3
|
+
import getMeta from '../../pg/funcs/getMeta.js';
|
|
4
|
+
|
|
5
|
+
export default async function dataDelete({
|
|
6
|
+
table, id,
|
|
7
|
+
}) {
|
|
8
|
+
const pg = getPG({ name: 'client' });
|
|
9
|
+
const { pk } = await getMeta(table);
|
|
10
|
+
if (!pg.tlist.includes(table)) return 'table not exist';
|
|
11
|
+
const delQuery = `delete from ${table} WHERE ${pk} = $1 returning *`;
|
|
12
|
+
// console.log(updateDataset);
|
|
13
|
+
const res = await pg.one(delQuery, [id]) || {};
|
|
14
|
+
return res;
|
|
15
|
+
}
|
package/crud/funcs/dataInsert.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import getPG from '../../pg/funcs/getPG.js';
|
|
2
|
-
import getMeta from '../../pg/funcs/getMeta.js';
|
|
3
|
-
|
|
4
|
-
export default async function dataInsert({ table, data }) {
|
|
5
|
-
const pg = getPG({ name: 'client' });
|
|
6
|
-
if (!data) return null;
|
|
7
|
-
const { columns } = await getMeta(table);
|
|
8
|
-
if (!columns) return null;
|
|
9
|
-
|
|
10
|
-
const names = columns.map((el) => el.name);
|
|
11
|
-
const filterData = Object.keys(data)
|
|
12
|
-
.filter((el) => data[el] && names.includes(el)).map((el) => [el, data[el]]);
|
|
13
|
-
|
|
14
|
-
const insertQuery = `insert into ${table}
|
|
15
|
-
|
|
16
|
-
( ${filterData?.map((key) => `"${key[0]}"`).join(',')})
|
|
17
|
-
|
|
18
|
-
values (${filterData?.map((key, i) => `$${i + 1}`).join(',')})
|
|
19
|
-
|
|
20
|
-
returning *`;
|
|
21
|
-
// console.log(updateDataset);
|
|
22
|
-
const res = await pg.one(insertQuery, [...filterData.map((el) => (typeof el[1] === 'object' ? JSON.stringify(el[1]) : el[1]))]) || {};
|
|
23
|
-
return res;
|
|
24
|
-
}
|
|
1
|
+
import getPG from '../../pg/funcs/getPG.js';
|
|
2
|
+
import getMeta from '../../pg/funcs/getMeta.js';
|
|
3
|
+
|
|
4
|
+
export default async function dataInsert({ table, data }) {
|
|
5
|
+
const pg = getPG({ name: 'client' });
|
|
6
|
+
if (!data) return null;
|
|
7
|
+
const { columns } = await getMeta(table);
|
|
8
|
+
if (!columns) return null;
|
|
9
|
+
|
|
10
|
+
const names = columns.map((el) => el.name);
|
|
11
|
+
const filterData = Object.keys(data)
|
|
12
|
+
.filter((el) => data[el] && names.includes(el)).map((el) => [el, data[el]]);
|
|
13
|
+
|
|
14
|
+
const insertQuery = `insert into ${table}
|
|
15
|
+
|
|
16
|
+
( ${filterData?.map((key) => `"${key[0]}"`).join(',')})
|
|
17
|
+
|
|
18
|
+
values (${filterData?.map((key, i) => `$${i + 1}`).join(',')})
|
|
19
|
+
|
|
20
|
+
returning *`;
|
|
21
|
+
// console.log(updateDataset);
|
|
22
|
+
const res = await pg.one(insertQuery, [...filterData.map((el) => (typeof el[1] === 'object' ? JSON.stringify(el[1]) : el[1]))]) || {};
|
|
23
|
+
return res;
|
|
24
|
+
}
|
package/crud/funcs/dataUpdate.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import getPG from '../../pg/funcs/getPG.js';
|
|
2
|
-
|
|
3
|
-
import getMeta from '../../pg/funcs/getMeta.js';
|
|
4
|
-
|
|
5
|
-
export default async function dataUpdate({
|
|
6
|
-
table, id, data,
|
|
7
|
-
}) {
|
|
8
|
-
const pg = getPG({ name: 'client' });
|
|
9
|
-
const { columns, pk } = await getMeta(table);
|
|
10
|
-
|
|
11
|
-
const names = columns.map((el) => el.name);
|
|
12
|
-
const filterData = Object.keys(data)
|
|
13
|
-
.filter((el) => data[el] && names.includes(el)).map((el) => [el, data[el]]);
|
|
14
|
-
|
|
15
|
-
const updateQuery = `UPDATE ${table} SET ${filterData?.map((key, i) => `"${key[0]}"=$${i + 2}`).join(',')}
|
|
16
|
-
WHERE ${pk} = $1 returning *`;
|
|
17
|
-
// console.log(updateDataset);
|
|
18
|
-
const res = await pg.one(updateQuery, [id, ...filterData.map((el) => (typeof el[1] === 'object' ? JSON.stringify(el[1]) : el[1]))]) || {};
|
|
19
|
-
return res;
|
|
20
|
-
}
|
|
1
|
+
import getPG from '../../pg/funcs/getPG.js';
|
|
2
|
+
|
|
3
|
+
import getMeta from '../../pg/funcs/getMeta.js';
|
|
4
|
+
|
|
5
|
+
export default async function dataUpdate({
|
|
6
|
+
table, id, data,
|
|
7
|
+
}) {
|
|
8
|
+
const pg = getPG({ name: 'client' });
|
|
9
|
+
const { columns, pk } = await getMeta(table);
|
|
10
|
+
|
|
11
|
+
const names = columns.map((el) => el.name);
|
|
12
|
+
const filterData = Object.keys(data)
|
|
13
|
+
.filter((el) => data[el] && names.includes(el)).map((el) => [el, data[el]]);
|
|
14
|
+
|
|
15
|
+
const updateQuery = `UPDATE ${table} SET ${filterData?.map((key, i) => `"${key[0]}"=$${i + 2}`).join(',')}
|
|
16
|
+
WHERE ${pk} = $1 returning *`;
|
|
17
|
+
// console.log(updateDataset);
|
|
18
|
+
const res = await pg.one(updateQuery, [id, ...filterData.map((el) => (typeof el[1] === 'object' ? JSON.stringify(el[1]) : el[1]))]) || {};
|
|
19
|
+
return res;
|
|
20
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { access } from 'fs/promises';
|
|
2
|
-
|
|
3
|
-
const isFileExists = async (filepath) => {
|
|
4
|
-
try {
|
|
5
|
-
await access(filepath);
|
|
6
|
-
return true;
|
|
7
|
-
}
|
|
8
|
-
catch (err) {
|
|
9
|
-
return false;
|
|
10
|
-
}
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export default isFileExists;
|
|
1
|
+
import { access } from 'fs/promises';
|
|
2
|
+
|
|
3
|
+
const isFileExists = async (filepath) => {
|
|
4
|
+
try {
|
|
5
|
+
await access(filepath);
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
catch (err) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export default isFileExists;
|
package/crud/index.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import getOPt from './funcs/getOpt.js';
|
|
2
|
-
import setOpt from './funcs/setOpt.js';
|
|
3
|
-
import isFileExists from './funcs/isFileExists.js';
|
|
4
|
-
import dataUpdate from './funcs/dataUpdate.js';
|
|
5
|
-
import dataInsert from './funcs/dataInsert.js';
|
|
6
|
-
|
|
7
|
-
import update from './controllers/update.js';
|
|
8
|
-
import insert from './controllers/insert.js';
|
|
9
|
-
import deleteCrud from './controllers/deleteCrud.js';
|
|
10
|
-
|
|
11
|
-
// import config from '../config.js';
|
|
12
|
-
|
|
13
|
-
async function plugin(fastify, config = {}) {
|
|
14
|
-
const prefix = config.prefix || '/api';
|
|
15
|
-
// funcs
|
|
16
|
-
fastify.decorate('setOpt', setOpt);
|
|
17
|
-
fastify.decorate('getOpt', getOPt);
|
|
18
|
-
fastify.decorate('dataUpdate', dataUpdate);
|
|
19
|
-
fastify.decorate('dataInsert', dataInsert);
|
|
20
|
-
|
|
21
|
-
fastify.decorate('isFileExists', isFileExists);
|
|
22
|
-
|
|
23
|
-
// api
|
|
24
|
-
fastify.put(`${prefix}/crud/:table/:id`, {}, update);
|
|
25
|
-
fastify.delete(`${prefix}/crud/:table/:id`, {}, deleteCrud);
|
|
26
|
-
fastify.post(`${prefix}/crud/:table`, {}, insert);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export default plugin;
|
|
1
|
+
import getOPt from './funcs/getOpt.js';
|
|
2
|
+
import setOpt from './funcs/setOpt.js';
|
|
3
|
+
import isFileExists from './funcs/isFileExists.js';
|
|
4
|
+
import dataUpdate from './funcs/dataUpdate.js';
|
|
5
|
+
import dataInsert from './funcs/dataInsert.js';
|
|
6
|
+
|
|
7
|
+
import update from './controllers/update.js';
|
|
8
|
+
import insert from './controllers/insert.js';
|
|
9
|
+
import deleteCrud from './controllers/deleteCrud.js';
|
|
10
|
+
|
|
11
|
+
// import config from '../config.js';
|
|
12
|
+
|
|
13
|
+
async function plugin(fastify, config = {}) {
|
|
14
|
+
const prefix = config.prefix || '/api';
|
|
15
|
+
// funcs
|
|
16
|
+
fastify.decorate('setOpt', setOpt);
|
|
17
|
+
fastify.decorate('getOpt', getOPt);
|
|
18
|
+
fastify.decorate('dataUpdate', dataUpdate);
|
|
19
|
+
fastify.decorate('dataInsert', dataInsert);
|
|
20
|
+
|
|
21
|
+
fastify.decorate('isFileExists', isFileExists);
|
|
22
|
+
|
|
23
|
+
// api
|
|
24
|
+
fastify.put(`${prefix}/crud/:table/:id`, {}, update);
|
|
25
|
+
fastify.delete(`${prefix}/crud/:table/:id`, {}, deleteCrud);
|
|
26
|
+
fastify.post(`${prefix}/crud/:table`, {}, insert);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export default plugin;
|
package/helper.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
// This file contains code that we reuse
|
|
2
|
-
// between our tests.
|
|
3
|
-
import Fastify from 'fastify';
|
|
4
|
-
import config from './test/config.js';
|
|
5
|
-
import appService from './index.js';
|
|
6
|
-
|
|
7
|
-
import rclient from './redis/client.js';
|
|
8
|
-
import pgClients from './pg/pgClients.js';
|
|
9
|
-
|
|
10
|
-
// automatically build and tear down our instance
|
|
11
|
-
async function build(t) {
|
|
12
|
-
// you can set all the options supported by the fastify CLI command
|
|
13
|
-
// const argv = [AppPath]
|
|
14
|
-
process.env.NODE_ENV = 'production';
|
|
15
|
-
const app = Fastify({ logger: false });
|
|
16
|
-
app.register(appService, config);
|
|
17
|
-
// close the app after we are done
|
|
18
|
-
t.after(() => {
|
|
19
|
-
// console.log('close app');
|
|
20
|
-
pgClients.client.end();
|
|
21
|
-
rclient.quit();
|
|
22
|
-
app.close();
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
return app;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export default build;
|
|
1
|
+
// This file contains code that we reuse
|
|
2
|
+
// between our tests.
|
|
3
|
+
import Fastify from 'fastify';
|
|
4
|
+
import config from './test/config.js';
|
|
5
|
+
import appService from './index.js';
|
|
6
|
+
|
|
7
|
+
import rclient from './redis/client.js';
|
|
8
|
+
import pgClients from './pg/pgClients.js';
|
|
9
|
+
|
|
10
|
+
// automatically build and tear down our instance
|
|
11
|
+
async function build(t) {
|
|
12
|
+
// you can set all the options supported by the fastify CLI command
|
|
13
|
+
// const argv = [AppPath]
|
|
14
|
+
process.env.NODE_ENV = 'production';
|
|
15
|
+
const app = Fastify({ logger: false });
|
|
16
|
+
app.register(appService, config);
|
|
17
|
+
// close the app after we are done
|
|
18
|
+
t.after(() => {
|
|
19
|
+
// console.log('close app');
|
|
20
|
+
pgClients.client.end();
|
|
21
|
+
rclient.quit();
|
|
22
|
+
app.close();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
return app;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export default build;
|
package/index.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
// import pg from 'pg';
|
|
2
|
-
import fp from 'fastify-plugin';
|
|
3
|
-
import config from './config.js';
|
|
4
|
-
// import rclient from './redis/client.js';
|
|
5
|
-
|
|
6
|
-
import redisPlugin from './redis/index.js';
|
|
7
|
-
import pgPlugin from './pg/index.js';
|
|
8
|
-
import tablePlugin from './table/index.js';
|
|
9
|
-
import crudPlugin from './crud/index.js';
|
|
10
|
-
|
|
11
|
-
async function plugin(fastify, opt) {
|
|
12
|
-
// console.log(opt);
|
|
13
|
-
config.pg = opt.pg;
|
|
14
|
-
config.redis = opt.redis;
|
|
15
|
-
|
|
16
|
-
redisPlugin(fastify);
|
|
17
|
-
await pgPlugin(fastify, opt);
|
|
18
|
-
tablePlugin(fastify, opt);
|
|
19
|
-
crudPlugin(fastify, opt);
|
|
20
|
-
}
|
|
21
|
-
export default fp(plugin);
|
|
22
|
-
// export { rclient };
|
|
1
|
+
// import pg from 'pg';
|
|
2
|
+
import fp from 'fastify-plugin';
|
|
3
|
+
import config from './config.js';
|
|
4
|
+
// import rclient from './redis/client.js';
|
|
5
|
+
|
|
6
|
+
import redisPlugin from './redis/index.js';
|
|
7
|
+
import pgPlugin from './pg/index.js';
|
|
8
|
+
import tablePlugin from './table/index.js';
|
|
9
|
+
import crudPlugin from './crud/index.js';
|
|
10
|
+
|
|
11
|
+
async function plugin(fastify, opt) {
|
|
12
|
+
// console.log(opt);
|
|
13
|
+
config.pg = opt.pg;
|
|
14
|
+
config.redis = opt.redis;
|
|
15
|
+
|
|
16
|
+
redisPlugin(fastify);
|
|
17
|
+
await pgPlugin(fastify, opt);
|
|
18
|
+
tablePlugin(fastify, opt);
|
|
19
|
+
crudPlugin(fastify, opt);
|
|
20
|
+
}
|
|
21
|
+
export default fp(plugin);
|
|
22
|
+
// export { rclient };
|
package/package.json
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@opengis/fastify-table",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"type": "module",
|
|
5
|
-
"description": "core-plugins",
|
|
6
|
-
"main": "index.js",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
|
|
9
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
10
|
-
},
|
|
11
|
-
"dependencies": {
|
|
12
|
-
"ioredis": "^5.3.2",
|
|
13
|
-
"fastify": "^4.26.1",
|
|
14
|
-
"fastify-plugin": "^4.0.0",
|
|
15
|
-
"pg": "^8.11.3"
|
|
16
|
-
},
|
|
17
|
-
"devDependencies": {
|
|
18
|
-
"eslint": "^8.49.0",
|
|
19
|
-
"eslint-config-airbnb": "^19.0.4"
|
|
20
|
-
},
|
|
21
|
-
"author": "Softpro",
|
|
22
|
-
"license": "ISC"
|
|
1
|
+
{
|
|
2
|
+
"name": "@opengis/fastify-table",
|
|
3
|
+
"version": "1.0.5",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "core-plugins",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
|
|
9
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"ioredis": "^5.3.2",
|
|
13
|
+
"fastify": "^4.26.1",
|
|
14
|
+
"fastify-plugin": "^4.0.0",
|
|
15
|
+
"pg": "^8.11.3"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"eslint": "^8.49.0",
|
|
19
|
+
"eslint-config-airbnb": "^19.0.4"
|
|
20
|
+
},
|
|
21
|
+
"author": "Softpro",
|
|
22
|
+
"license": "ISC"
|
|
23
23
|
}
|