Skip to content

Commit 2c16697

Browse files
author
khanh2906
committed
update version 0.6.19
1 parent 2025609 commit 2c16697

File tree

13 files changed

+142
-25
lines changed

13 files changed

+142
-25
lines changed

SECURITY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
| ------- | ------------------ |
77
| 0.5.3 | :white_check_mark: |
88
| 0.6.18 | :white_check_mark: |
9+
| 0.6.19 | :white_check_mark: |
910

1011

1112
## Reporting a Vulnerability

lib/stubs/elements/ORM/nosql/mongoDb/User.stub

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const mongoose = require("@iKernel/database")();
1+
const mongoose = require("@iKernel/database").get();
22
const Schema = mongoose.Schema;
33
const auth = require("@iKernel/auth");
44

lib/stubs/elements/ORM/sql/User.stub

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const { Sequelize, DataTypes } = require("sequelize");
2-
const sequelize = require("@iKernel/database")();
2+
const sequelize = require("@iKernel/database").get();
33
const auth = require("@iKernel/auth");
44

55
const User = sequelize.define("users", {

lib/stubs/template/jsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@
3737
}
3838
},
3939
"include": [
40-
"src/**/*"],
40+
"src/**/*"
41+
],
4142
"exclude": [
4243
"node_modules",
4344
"dist"
4445
]
45-
4646
}

lib/stubs/template/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"name": "bamimi",
3-
"version": "0.6.18",
3+
"version": "0.6.19",
44
"description": "Power framework for nodejs",
55
"main": "src/server.js",
6-
"bamimiVersion": "0.6.18",
6+
"bamimiVersion": "0.6.19",
77
"bin": {
88
"bamimi-enjoy-": "./dist/routes/cli/index.js",
99
"bamimi-enjoy-dev": "./src/routes/cli/index.js"

lib/stubs/template/src/configs/file.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ module.exports = {
1313
tmp: {
1414
url: '',
1515
folder: path.join(__dirname, './../storage/tmp')
16-
},
17-
s3: {
18-
url: process.env.AWS_BUCKET_URL ?? "",
19-
bucket: process.env.AWS_BUCKET_NAME,
2016
}
2117
}
2218
};

lib/stubs/template/src/kernel/cache/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
"use strict";
22
const cache = require("@iConfigs/cache")
3-
const redisInit = require("./redis")
43

54
const getStorage = (storage = null) => {
65
switch (storage) {
76
case 'redis':
8-
return redisInit();
7+
return require("./redis")();
98
default:
109
return getStorage(cache.use)
1110
}

lib/stubs/template/src/kernel/database/index.js

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,66 @@
11

2+
"use strict";
3+
/**
4+
* Module `DB`
5+
*
6+
* Module to init and return Database connection with SQL or NoSQL.
7+
* Auto get config from `@iConfigs/database`.
8+
*
9+
* @module DB
10+
*
11+
* @requires @iConfigs/database - Config of database
12+
* @requires sequelize
13+
* @requires mongodb
14+
*/
15+
216
const config = require("@iConfigs/database");
317

4-
const getDB = ({ useDatabase }) => {
18+
/**
19+
* Connect and get DB with params
20+
*
21+
* @function get
22+
*
23+
* @param {Object} options - To determine database information
24+
* @param {string} options.useDatabase - Type of Database (e.g: "sql", "nosql").
25+
* If no specified, module will use default value
26+
* from `config.useDatabase`.
27+
*
28+
* @returns {Object} - Connection Database Object:
29+
* - With SQL: return Sequelize instance.
30+
* - With NoSQL (e.g: MongoDB): return flexible connection (default is Mongoose)
31+
*
32+
* @example
33+
* Use default value from config
34+
* const db = require('@iKernel/database').get();
35+
*
36+
* @example
37+
* // Use SQL (Sequelize)
38+
* const db = require('@iKernel/database').get({ useDatabase: 'sql' });
39+
*
40+
* @example
41+
* // Use NoSQL (MongoDB)
42+
* const db = require('@iKernel/database').get({ useDatabase: 'nosql' });
43+
*/
44+
exports.get = ({ useDatabase }) => {
45+
/**
46+
* Many connection database method
47+
*/
548
const useDBs = {
49+
/**
50+
* SQL Connection
51+
*
52+
* @function sql
53+
* @returns {require("sequelize")} - Return instance of Sequelize
54+
*/
655
sql: function () {
756
return require("./sequelize")(config.sql[config.sql.environment])
857
},
58+
/**
59+
* NoSQL Connection
60+
*
61+
* @function nosql
62+
* @returns {Object} - Return mongoose or other (future update).
63+
*/
964
nosql: function () {
1065
switch (config.nosql.connection) {
1166
case "mongodb":
@@ -18,6 +73,4 @@ const getDB = ({ useDatabase }) => {
1873
const db = useDatabase ? useDBs[useDatabase]() : useDBs[config.useDatabase]();
1974

2075
return db
21-
}
22-
23-
module.exports = getDB;
76+
}

lib/stubs/template/src/kernel/database/sequelize.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
const { Sequelize } = require("sequelize");
2+
3+
let sequelize = null;
14

25
module.exports = (config) => {
3-
const { Sequelize } = require("sequelize");
4-
const sequelize = new Sequelize(config);
6+
if (!sequelize) {
7+
sequelize = new Sequelize(config);
8+
9+
}
510
sequelize.authenticate()
611
.then(() => {
712
console.log("Connection has been established successfully.");

lib/stubs/template/src/kernel/index.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ exports.middleware = {
1111
common: {
1212
before: [
1313
/**
14-
* Update powerd by
14+
* Update Powered by
1515
*/
1616
async (req, res, next) => {
1717
res.setHeader('X-Powered-By', 'Bamimi');
@@ -74,7 +74,9 @@ exports.middleware = {
7474
next();
7575
},
7676
/**
77-
* method override
77+
* ****************************
78+
* CSRF
79+
* ****************************
7880
*/
7981
csrf.generate({
8082
tokenLength: 24,
@@ -90,9 +92,18 @@ exports.middleware = {
9092
}
9193
}
9294
}),
93-
9495
csrf.setTokenLocalsParam,
96+
/**
97+
* ****************************
98+
* Response handle
99+
* ****************************
100+
*/
95101
require("@iKernel/response/web"),
102+
/**
103+
* ****************************
104+
* method override
105+
* ****************************
106+
*/
96107
methodOverride('X-HTTP-Method'),
97108
methodOverride('X-HTTP-Method-Override'),
98109
methodOverride('X-Method-Override'),

lib/stubs/template/src/kernel/interface/apis/index.js

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,61 @@
11
"use strict";
2+
/**
3+
* Module `interface api handle`
4+
*
5+
* Module to init and return Database connection with SQL or NoSQL.
6+
* Auto get config from `@iConfigs/database`.
7+
*
8+
* @module
9+
*
10+
* @requires structure - structure of response
11+
*/
212
const { content: ifaContent, message: ifaMsg } = require("./structure");
3-
413
/**
14+
* @typedef {{code: number, content: string}} meta
15+
* @typedef {{meta: meta, data: Object}} messageData
16+
* @typedef {{meta: meta, errors: Object}} messageError
17+
*/
18+
/**
19+
* Get format response
20+
*
21+
* @function handle
22+
*
23+
* @param {Number} status - state of response
24+
* @param {Object} data - response data
25+
*
26+
* @returns {messageData | messageError} {@link messageData} | {@link messageError }
27+
*
28+
* @example
29+
* Import module
30+
* const { handle } = require("@iKernel/interface/api")
31+
*
32+
* @example
33+
* // With data
34+
* const response = handle(200, {msg: "OK la"})
35+
* console.log(response) -
36+
* {
37+
* meta: {
38+
* status: 200,
39+
* content: "OK"
40+
* },
41+
* data: {
42+
* msg: "Ok la"
43+
* }
44+
* }
545
*
6-
* @param {Number} status
7-
* @param {Object} data
46+
* @example
47+
* // With error
48+
* const response = handle(403, [{"msg": "Not admin"}])
49+
* console.log(response) -
50+
* {
51+
* meta: {
52+
* status: 403,
53+
* content: "Forbidden"
54+
* },
55+
* errors: [{
56+
* msg: "Not admin"
57+
* }]
58+
* }
859
*/
960
exports.handle = (status, data = null) => {
1061

lib/stubs/template/src/libs/file.lib.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ const remove = async ({ pathFile, storageType }) => {
6464
}
6565
},
6666
};
67+
6768
return storageType ? await storages[storageType]() : await storages[config.use]();
6869
};
6970

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@knfs-tech/bamimi-cli",
3-
"version": "0.6.18",
3+
"version": "0.6.19",
44
"description": "Command line of Bamimi framework",
55
"bin": {
66
"bamimi-cli": "./bin/cli.js"

0 commit comments

Comments
 (0)