beech-api 3.5.12 → 3.7.23
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 +400 -185
- package/index.js +2 -3
- package/package.json +9 -5
- package/packages/cli/beech +2 -2
- package/packages/cli/bin/{beech.js → beech-app.js} +86 -28
- package/packages/cli/bin/beech-service.js +40 -212
- package/packages/cli/core/auth/Credentials.js +76 -35
- package/packages/cli/core/auth/Passport.js +318 -188
- package/packages/cli/core/auth/_Request.js +12 -0
- package/packages/cli/core/configure/_gitignore +9 -1
- package/packages/cli/core/configure/app.config-basic.js +10 -10
- package/packages/cli/core/configure/app.config-sequelize.js +12 -12
- package/packages/cli/core/configure/beech.config.js +8 -0
- package/packages/cli/core/configure/global.config-basic.js +4 -4
- package/packages/cli/core/configure/global.config-sequelize.js +4 -4
- package/packages/cli/core/configure/passport.config.js +5 -15
- package/packages/cli/core/databases/mysql.js +53 -29
- package/packages/cli/core/databases/sequelize.js +135 -107
- package/packages/cli/core/databases/test.js +168 -0
- package/packages/cli/core/file-walk/file-walk.js +31 -14
- package/packages/cli/core/generator/_add-on +15 -2
- package/packages/cli/core/generator/_endpoints +15 -82
- package/packages/cli/core/generator/_endpoints_basic +39 -0
- package/packages/cli/core/generator/_help +12 -11
- package/packages/cli/core/generator/_help_create +11 -0
- package/packages/cli/core/generator/{_service → _help_service} +4 -1
- package/packages/cli/core/generator/_models +20 -15
- package/packages/cli/core/generator/{_basic-models → _models_basic} +0 -2
- package/packages/cli/core/generator/_package +4 -3
- package/packages/cli/core/generator/index.js +302 -95
- package/packages/cli/core/helpers/math.js +55 -0
- package/packages/cli/core/helpers/poolEntity.js +31 -0
- package/packages/cli/core/index.js +96 -28
- package/packages/cli/core/origin/index.js +2 -0
- package/packages/cli/core/origin/whitelist/cors.js +91 -0
- package/packages/cli/core/services/http.express.js +338 -203
- package/packages/cli/core/test/utils.js +5 -5
- package/packages/lib/index.js +4 -0
- package/packages/lib/src/endpoint.js +98 -0
- package/packages/lib/src/salt.js +3 -0
- package/packages/lib/src/schema.js +62 -0
- package/packages/lib/src/user.js +196 -0
- package/packages/cli/core/generator/_create +0 -7
- package/packages/lib/beech.js +0 -136
- package/packages/lib/salt.js +0 -3
- package/packages/package.json +0 -20
- package/packages/src-/Add-on.js +0 -9
- package/packages/src-/endpoints/hello-endpoints.js +0 -118
- package/packages/src-/endpoints/test2-endpoints.js +0 -75
- package/packages/src-/endpoints/testSequalize-endpoints.js +0 -23
- package/packages/src-/helpers/Test2.js +0 -11
- package/packages/src-/helpers/my/Test.js +0 -11
- package/packages/src-/helpers/my/Test2.js +0 -11
- package/packages/src-/helpers/my/Test3.js +0 -11
- package/packages/src-/helpers/my/Test4.js +0 -11
- package/packages/src-/models/Jubu.js +0 -29
- package/packages/src-/models/Jubu2.js +0 -20
- package/packages/src-/models/Map_master.js +0 -22
- package/packages/src-/models/Test.js +0 -29
- package/packages/src-/models/Test2.js +0 -29
- package/packages/src-/models/User2Sequelize.js +0 -23
- package/packages/src-/models/Users-sqlite.js +0 -21
- package/packages/src-/models/Users.js +0 -53
- package/packages/src-/models/Uuuuuxxx.js +0 -23
- package/packages/src-/models/xxx/Uuuuuxxx.js +0 -23
- /package/packages/cli/core/generator/{_basic-helpers → _helpers_basic} +0 -0
|
@@ -5,14 +5,14 @@ module.exports = {
|
|
|
5
5
|
* @exports app_port : Listening for start service
|
|
6
6
|
* @exports app_host : Server http localhost
|
|
7
7
|
* @exports client_host : Production http client host
|
|
8
|
-
* @exports
|
|
8
|
+
* @exports app_key : App key for request with endpoints
|
|
9
9
|
*
|
|
10
10
|
*/
|
|
11
11
|
main_config: {
|
|
12
12
|
app_port: 9000,
|
|
13
13
|
app_host: "localhost",
|
|
14
14
|
client_host: "http://0.0.0.0:9000",
|
|
15
|
-
|
|
15
|
+
app_key: [ "2cc118cd91b52ff99e3c005ddced76fb" ]
|
|
16
16
|
},
|
|
17
17
|
|
|
18
18
|
// Add-on it's work when enabled. You can enable add-on by run CMD `$ beech add-on init`.
|
|
@@ -23,8 +23,8 @@ module.exports = {
|
|
|
23
23
|
*
|
|
24
24
|
* @exports name : The Connection name
|
|
25
25
|
* @exports host : The Host address
|
|
26
|
-
* @exports username : The Host username connection
|
|
27
|
-
* @exports password : Host The password connection
|
|
26
|
+
* @exports username : The Host username connection (Hash needed)
|
|
27
|
+
* @exports password : Host The password connection (Hash needed)
|
|
28
28
|
* @exports database : The database name
|
|
29
29
|
* @exports port : The sql port (default 3306)
|
|
30
30
|
* @exports charset : The character encoding
|
|
@@ -34,9 +34,9 @@ module.exports = {
|
|
|
34
34
|
database_config: [
|
|
35
35
|
{
|
|
36
36
|
name: "default_db",
|
|
37
|
-
host: "
|
|
38
|
-
username: "
|
|
39
|
-
password: "",
|
|
37
|
+
host: "localhost",
|
|
38
|
+
username: "DB_USERNAME_HASH",
|
|
39
|
+
password: "DB_PASSWORD_HASH",
|
|
40
40
|
database: "example1_db",
|
|
41
41
|
port: "3306",
|
|
42
42
|
charset: "utf8",
|
|
@@ -44,9 +44,9 @@ module.exports = {
|
|
|
44
44
|
},
|
|
45
45
|
{
|
|
46
46
|
name: "second_db",
|
|
47
|
-
host: "
|
|
48
|
-
username: "
|
|
49
|
-
password: "",
|
|
47
|
+
host: "localhost",
|
|
48
|
+
username: "DB_USERNAME_HASH",
|
|
49
|
+
password: "DB_PASSWORD_HASH",
|
|
50
50
|
database: "example2_db",
|
|
51
51
|
port: "3306",
|
|
52
52
|
charset: "utf8",
|
|
@@ -5,14 +5,14 @@ module.exports = {
|
|
|
5
5
|
* @exports app_port : Listening for start service
|
|
6
6
|
* @exports app_host : Server http localhost
|
|
7
7
|
* @exports client_host : Production http client host
|
|
8
|
-
* @exports
|
|
8
|
+
* @exports app_key : App key for request with endpoints
|
|
9
9
|
*
|
|
10
10
|
*/
|
|
11
11
|
main_config: {
|
|
12
12
|
app_port: 9000,
|
|
13
13
|
app_host: "localhost",
|
|
14
14
|
client_host: "http://0.0.0.0:9000",
|
|
15
|
-
|
|
15
|
+
app_key: [ "2cc118cd91b52ff99e3c005ddced76fb" ]
|
|
16
16
|
},
|
|
17
17
|
|
|
18
18
|
// Add-on it's work when enabled. You can enable add-on by run CMD `$ beech add-on init`.
|
|
@@ -25,14 +25,14 @@ module.exports = {
|
|
|
25
25
|
* @exports dialect The engine SQL connection one of 'mysql' | 'sqlite' | 'mariadb' | 'postgres' | 'mssql'
|
|
26
26
|
* The Dialect need of the following:
|
|
27
27
|
* - $ npm install --save pg pg-hstore # Postgres
|
|
28
|
-
* - $ npm install --save mysql2
|
|
28
|
+
* - $ npm install --save mysql2 (MySQL suppport version ^5.7, Learn more : https://sequelize.org/releases/#mysql-support-table)
|
|
29
29
|
* - $ npm install --save mariadb
|
|
30
|
-
* - $ npm install --save sqlite3 (Need NodeJS
|
|
30
|
+
* - $ npm install --save sqlite3 (Need NodeJS ^12.x)
|
|
31
31
|
* - $ npm install --save tedious # Microsoft SQL Server (Need NodeJS v14.x)
|
|
32
32
|
* @exports name The Connection name
|
|
33
33
|
* @exports host The Host address
|
|
34
|
-
* @exports username The Host username connection
|
|
35
|
-
* @exports password Host The password connection
|
|
34
|
+
* @exports username The Host username connection (Hash needed)
|
|
35
|
+
* @exports password Host The password connection (Hash needed)
|
|
36
36
|
* @exports database The database name
|
|
37
37
|
* @exports port The sql port (default port by dialect mysql:3306, marialdb:3306, postgres:5432 and mssql:1433)
|
|
38
38
|
* @exports define The character encoding and optional. See more: https://sequelize.org/docs/v6/other-topics/dialect-specific-things/
|
|
@@ -45,9 +45,9 @@ module.exports = {
|
|
|
45
45
|
{
|
|
46
46
|
dialect: "mysql",
|
|
47
47
|
name: "default_db",
|
|
48
|
-
host: "
|
|
49
|
-
username: "
|
|
50
|
-
password: "",
|
|
48
|
+
host: "localhost",
|
|
49
|
+
username: "DB_USERNAME_HASH",
|
|
50
|
+
password: "DB_PASSWORD_HASH",
|
|
51
51
|
database: "example1_db",
|
|
52
52
|
port: "3306",
|
|
53
53
|
define: {
|
|
@@ -67,9 +67,9 @@ module.exports = {
|
|
|
67
67
|
{
|
|
68
68
|
dialect: "mssql",
|
|
69
69
|
name: "thirdth_db",
|
|
70
|
-
host: "
|
|
71
|
-
username: "
|
|
72
|
-
password: "",
|
|
70
|
+
host: "localhost",
|
|
71
|
+
username: "DB_USERNAME_HASH",
|
|
72
|
+
password: "DB_PASSWORD_HASH",
|
|
73
73
|
database: "example3_db",
|
|
74
74
|
port: "1433",
|
|
75
75
|
define: {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
module.exports.init = () => {
|
|
2
|
-
//
|
|
2
|
+
// Pool base config
|
|
3
3
|
global.pool_base = "basic"; // one of "basic" | "sequelize"
|
|
4
4
|
|
|
5
|
-
//
|
|
6
|
-
global.
|
|
5
|
+
// Example declare global varables library, config and anything
|
|
6
|
+
global.App = "myApp";
|
|
7
7
|
|
|
8
|
-
//
|
|
8
|
+
// Anything global config for you ...
|
|
9
9
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
module.exports.init = () => {
|
|
2
|
-
//
|
|
2
|
+
// Pool base config
|
|
3
3
|
global.pool_base = "sequelize"; // one of "basic" | "sequelize"
|
|
4
4
|
|
|
5
|
-
//
|
|
6
|
-
global.
|
|
5
|
+
// Example declare global varables library, config and anything
|
|
6
|
+
global.App = "myApp";
|
|
7
7
|
|
|
8
|
-
//
|
|
8
|
+
// Anything global config for you ...
|
|
9
9
|
}
|
|
@@ -19,12 +19,12 @@ module.exports = {
|
|
|
19
19
|
// The fields for authenticate, default fields: (`username` and `password`)
|
|
20
20
|
username_field: "",
|
|
21
21
|
password_field: "",
|
|
22
|
-
//
|
|
22
|
+
// JWT playload data
|
|
23
23
|
fields: []
|
|
24
24
|
},
|
|
25
25
|
|
|
26
|
-
// Allow using with
|
|
27
|
-
|
|
26
|
+
// Allow using with app_key request (Every request must be using the app_key header)
|
|
27
|
+
app_key_allow: true,
|
|
28
28
|
|
|
29
29
|
// Official strategy
|
|
30
30
|
strategy: {
|
|
@@ -37,13 +37,9 @@ module.exports = {
|
|
|
37
37
|
google: {
|
|
38
38
|
// Allow using google strategy
|
|
39
39
|
allow: false,
|
|
40
|
-
//
|
|
40
|
+
// Authen profile store fields available: `google_id`, `name`, `email`, `photos`, `locate`
|
|
41
41
|
local_profile_fields: {
|
|
42
42
|
google_id: "google_id", // Google ID field, default field name: `google_id`
|
|
43
|
-
name: "name",
|
|
44
|
-
email: "email",
|
|
45
|
-
photos: "profile_url",
|
|
46
|
-
locate: "" // If you not store set to null
|
|
47
43
|
},
|
|
48
44
|
// Google development Credentials OAuth 2.0 Client IDs
|
|
49
45
|
client_id: "GOOGLE_CLIENT_ID",
|
|
@@ -65,19 +61,13 @@ module.exports = {
|
|
|
65
61
|
facebook: {
|
|
66
62
|
// Allow using facebook strategy
|
|
67
63
|
allow: false,
|
|
68
|
-
//
|
|
64
|
+
// Authen profile store fields available: `facebook_id`, `name`, `email`, `photos`, `locate`
|
|
69
65
|
local_profile_fields: {
|
|
70
66
|
facebook_id: "facebook_id", // Facebook ID field, default field name: `facebook_id`
|
|
71
|
-
name: "name",
|
|
72
|
-
email: "email",
|
|
73
|
-
photos: "profile_url",
|
|
74
|
-
locate: "" // If you not store set to null
|
|
75
67
|
},
|
|
76
68
|
// Facebook development Credentials OAuth 2.0
|
|
77
69
|
app_id: "FACEBOOK_APP_ID",
|
|
78
70
|
app_secret: "FACEBOOK_APP_SECRET",
|
|
79
|
-
// Allow Permissions facebook profile fields: see more (https://developers.facebook.com/docs/graph-api/reference/v13.0/user#readperms)
|
|
80
|
-
profileFieldsAllow: [ 'id', 'displayName', 'name', 'photos', 'email', 'location' ],
|
|
81
71
|
// Callback endpoint default `/facebook/callback`
|
|
82
72
|
callbackURL: "",
|
|
83
73
|
// Failure redirect to your route
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const mysql = require("mysql");
|
|
2
|
+
const { DeHashIt, M, X } = require(__dirname + "/../helpers/math");
|
|
2
3
|
global.sql = {};
|
|
3
4
|
|
|
4
5
|
exports.connect = () => {
|
|
@@ -22,40 +23,63 @@ mysqlInProcess = (database_config, headDbShow, cb) => {
|
|
|
22
23
|
let val = database_config.shift();
|
|
23
24
|
// checking turn on db connect
|
|
24
25
|
if (val.is_connect) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
database: val.database,
|
|
31
|
-
charset: val.charset,
|
|
32
|
-
port: val.port
|
|
33
|
-
})
|
|
34
|
-
// db connecting
|
|
35
|
-
connection.connect(err => {
|
|
36
|
-
if (!err) {
|
|
37
|
-
// show only one text db connnections
|
|
38
|
-
if (headDbShow) {
|
|
39
|
-
console.log('\n[102m[90m Passed [0m [0mDatabase is connected at:');
|
|
40
|
-
headDbShow = false;
|
|
26
|
+
const promise = new Promise((resolve) => {
|
|
27
|
+
// check hash ?
|
|
28
|
+
if(val.username && val.password) {
|
|
29
|
+
if(val.username.length < 55 || val.password < 55) {
|
|
30
|
+
return cb("Error: No Hash access for connect to database.\n", null);
|
|
41
31
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
cb(e, true);
|
|
32
|
+
let accessDb = [];
|
|
33
|
+
[val.username, val.password].map((e, k) => {
|
|
34
|
+
DeHashIt(e.toString(), null, (17).toString().slice(0,-1).length, (err, d) => {
|
|
35
|
+
if(!err) {
|
|
36
|
+
accessDb.push(d.split("sh,")[1].split(M(X).toString().slice(0,2)+M(X).toString())[0].slice(0,-1));
|
|
37
|
+
}
|
|
49
38
|
});
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
39
|
+
if(k+1==2) {
|
|
40
|
+
resolve(accessDb);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
54
43
|
} else {
|
|
55
|
-
|
|
56
|
-
cb(err, null);
|
|
44
|
+
resolve([null, null]);
|
|
57
45
|
}
|
|
58
46
|
});
|
|
47
|
+
Promise.all([promise]).then(final => {
|
|
48
|
+
// db connection config
|
|
49
|
+
let connection = mysql.createConnection({
|
|
50
|
+
host: val.host,
|
|
51
|
+
user: final[0][0],
|
|
52
|
+
password: final[0][1],
|
|
53
|
+
database: val.database,
|
|
54
|
+
charset: val.charset,
|
|
55
|
+
port: val.port
|
|
56
|
+
});
|
|
57
|
+
// db connecting
|
|
58
|
+
connection.connect(err => {
|
|
59
|
+
if (!err) {
|
|
60
|
+
// show only one text db connnections
|
|
61
|
+
if (headDbShow) {
|
|
62
|
+
console.log('[102m[90m Passed [0m [0mDatabase is connected at:');
|
|
63
|
+
headDbShow = false;
|
|
64
|
+
}
|
|
65
|
+
// declare to global mysql variable
|
|
66
|
+
sql[ val.name ] = connection;
|
|
67
|
+
console.log('-[36m ' + val.name + ' [0m->[93m ' + connection.config.database + ':' + connection.config.port + '[0m');
|
|
68
|
+
// checking recursive database connection
|
|
69
|
+
if (database_config.length > 0) {
|
|
70
|
+
mysqlInProcess(database_config, headDbShow, e => {
|
|
71
|
+
cb(e, true);
|
|
72
|
+
});
|
|
73
|
+
} else {
|
|
74
|
+
// perfectly recursive
|
|
75
|
+
cb(err, true);
|
|
76
|
+
}
|
|
77
|
+
} else {
|
|
78
|
+
console.log('[101m Failed [0m [91mDatabase `' + val.name + '` is connect failed.[0m');
|
|
79
|
+
cb(err, null);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
});
|
|
59
83
|
} else {
|
|
60
84
|
if (database_config.length > 0) {
|
|
61
85
|
mysqlInProcess(database_config, headDbShow, e => {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const Sequelize = require('sequelize');
|
|
2
|
+
const { DeHashIt, M, X } = require(__dirname + "/../helpers/math");
|
|
2
3
|
global.sql = {};
|
|
3
4
|
|
|
4
5
|
exports.connect = () => {
|
|
@@ -22,117 +23,144 @@ connectInProcess = async (database_config, headDbShow, cb) => {
|
|
|
22
23
|
let val = database_config.shift();
|
|
23
24
|
// checking turn on db connect
|
|
24
25
|
if (val.is_connect) {
|
|
25
|
-
const
|
|
26
|
-
//
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
// containing a UNIX socket to connect over
|
|
31
|
-
// host: '/sockets/psql_sockets'.
|
|
32
|
-
host: val.host,
|
|
33
|
-
username: val.username,
|
|
34
|
-
password: val.password,
|
|
35
|
-
database: val.database,
|
|
36
|
-
port: val.port,
|
|
37
|
-
|
|
38
|
-
// the storage engine for sqlite
|
|
39
|
-
// - default ':memory:'
|
|
40
|
-
storage: val.storage || ":memory:",
|
|
41
|
-
|
|
42
|
-
// custom protocol; default: 'tcp'
|
|
43
|
-
// postgres only, useful for Heroku
|
|
44
|
-
protocol: val.protocol || null,
|
|
45
|
-
// disable logging or provide a custom logging function; default: console.log
|
|
46
|
-
logging: val.logging || false,
|
|
47
|
-
|
|
48
|
-
// you can also pass any dialect options to the underlying dialect library
|
|
49
|
-
// - default is empty
|
|
50
|
-
// - currently supported: 'mysql', 'postgres', 'mssql'
|
|
51
|
-
dialectOptions: {
|
|
52
|
-
socketPath: ((val.dialectOptions) ? ((val.dialectOptions.socketPath) ? val.dialectOptions.socketPath : "") : ""), //Applications/MAMP/tmp/mysql/mysql.sock
|
|
53
|
-
supportBigNumbers: ((val.dialectOptions) ? ((val.dialectOptions.supportBigNumbers) ? val.dialectOptions.supportBigNumbers : false) : false),
|
|
54
|
-
bigNumberStrings: ((val.dialectOptions) ? ((val.dialectOptions.bigNumberStrings) ? val.dialectOptions.bigNumberStrings : false) : false),
|
|
55
|
-
options: ((val.dialectOptions) ? ((val.dialectOptions.options) ? ({ encrypt: false, ...val.dialectOptions.options }) : { encrypt: false }) : { encrypt: false }),
|
|
56
|
-
},
|
|
57
|
-
|
|
58
|
-
// disable inserting undefined values as NULL
|
|
59
|
-
// - default: false
|
|
60
|
-
omitNull: val.omitNull || false,
|
|
61
|
-
|
|
62
|
-
// a flag for using a native library or not.
|
|
63
|
-
// in the case of 'pg' -- set this to true will allow SSL support
|
|
64
|
-
// - default: false
|
|
65
|
-
native: val.native || false,
|
|
66
|
-
|
|
67
|
-
// Specify options, which are used when sequelize.define is called.
|
|
68
|
-
// The following example:
|
|
69
|
-
// define: { timestamps: false }
|
|
70
|
-
// is basically the same as:
|
|
71
|
-
// Model.init(attributes, { timestamps: false });
|
|
72
|
-
// sequelize.define(name, attributes, { timestamps: false });
|
|
73
|
-
// so defining the timestamps for each model will be not necessary
|
|
74
|
-
define: {
|
|
75
|
-
underscored: ((val.define) ? ((val.define.underscored) ? val.define.underscored : false) : false),
|
|
76
|
-
freezeTableName: ((val.define) ? ((val.define.freezeTableName === false) ? val.define.freezeTableName : true) : true),
|
|
77
|
-
charset: ((val.define) ? ((val.define.charset) ? val.define.charset : "utf8") : "utf8"),
|
|
78
|
-
dialectOptions: {
|
|
79
|
-
collate: ((val.define) ? ((val.define.dialectOptions) ? ((val.define.dialectOptions.timestamps) ? val.define.dialectOptions.timestamps : "utf8_general_ci") : "utf8_general_ci") : "utf8_general_ci"),
|
|
80
|
-
},
|
|
81
|
-
timestamps: ((val.define) ? ((val.define.timestamps) ? val.define.timestamps : false) : false),
|
|
82
|
-
},
|
|
83
|
-
|
|
84
|
-
// similar for sync: you can define this to always force sync for models
|
|
85
|
-
sync: {
|
|
86
|
-
force: ((val.sync) ? ((val.sync.force) ? val.sync.force : false) : false),
|
|
87
|
-
},
|
|
88
|
-
|
|
89
|
-
// pool configuration used to pool database connections
|
|
90
|
-
pool: {
|
|
91
|
-
max: ((val.pool) ? ((val.pool.max) ? val.pool.max : 5) : 5),
|
|
92
|
-
idle: ((val.pool) ? ((val.pool.idle) ? val.pool.idle : 30000) : 30000),
|
|
93
|
-
acquire: ((val.pool) ? ((val.pool.acquire) ? val.pool.acquire : 60000) : 60000),
|
|
94
|
-
},
|
|
95
|
-
|
|
96
|
-
// isolation level of each transaction
|
|
97
|
-
// defaults to dialect default
|
|
98
|
-
isolationLevel: val.isolationLevel || "Transaction.ISOLATION_LEVELS.REPEATABLE_READ",
|
|
99
|
-
|
|
100
|
-
// JSON response
|
|
101
|
-
query: {
|
|
102
|
-
raw: ((val.query) ? ((val.query.raw) ? val.query.raw : true) : true),
|
|
103
|
-
nest: ((val.query) ? ((val.query.nest) ? val.query.nest : true) : true),
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
// connection
|
|
108
|
-
await sq.authenticate()
|
|
109
|
-
.then(() => {
|
|
110
|
-
// show only one text db connnections
|
|
111
|
-
if (headDbShow) {
|
|
112
|
-
console.log('\n[102m[90m Passed [0m [0mDatabase is connected at:');
|
|
113
|
-
headDbShow = false;
|
|
114
|
-
}
|
|
115
|
-
// create database pool
|
|
116
|
-
sql[ val.name ] = sq;
|
|
117
|
-
// checking dialect sql
|
|
118
|
-
if (val.dialect == "sqlite") {
|
|
119
|
-
console.log('- [91m[' + val.dialect + '] [0m[36m' + val.name + ' [0m->[93m ' + sq.options.storage + '[0m');
|
|
120
|
-
} else {
|
|
121
|
-
console.log('- [91m[' + val.dialect + '] [0m[36m' + val.name + ' [0m->[93m ' + sq.config.database + ':' + sq.config.port + '[0m');
|
|
26
|
+
const promise = new Promise((resolve) => {
|
|
27
|
+
// check hash ?
|
|
28
|
+
if(val.username && val.password) {
|
|
29
|
+
if(val.username.length < 55 || val.password < 55) {
|
|
30
|
+
return cb("Error: No Hash access for connect to database.\n", null);
|
|
122
31
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
32
|
+
let accessDb = [];
|
|
33
|
+
[val.username, val.password].map((e, k) => {
|
|
34
|
+
DeHashIt(e.toString(), null, (17).toString().slice(0,-1).length, (err, d) => {
|
|
35
|
+
if(!err) {
|
|
36
|
+
accessDb.push(d.split("sh,")[1].split(M(X).toString().slice(0,2)+M(X).toString())[0].slice(0,-1));
|
|
37
|
+
}
|
|
127
38
|
});
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
39
|
+
if(k+1==2) {
|
|
40
|
+
resolve(accessDb);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
} else {
|
|
44
|
+
resolve([null, null]);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
Promise.all([promise]).then(async (final) => {
|
|
48
|
+
const sq = await new Sequelize({
|
|
49
|
+
// one of 'mysql' | 'sqlite' | 'mariadb' | 'postgres' | 'mssql'
|
|
50
|
+
dialect: val.dialect || "mysql",
|
|
51
|
+
|
|
52
|
+
// for postgres, you can also specify an absolute path to a directory
|
|
53
|
+
// containing a UNIX socket to connect over
|
|
54
|
+
// host: '/sockets/psql_sockets'.
|
|
55
|
+
host: (val.host == "localhost" || val.host == "http://localhost") ? "127.0.0.1" : val.host,
|
|
56
|
+
username: final[0][0],
|
|
57
|
+
password: final[0][1],
|
|
58
|
+
database: val.database,
|
|
59
|
+
port: val.port,
|
|
60
|
+
|
|
61
|
+
// the storage engine for sqlite
|
|
62
|
+
// - default ':memory:'
|
|
63
|
+
storage: val.storage || ":memory:",
|
|
64
|
+
|
|
65
|
+
// custom protocol; default: 'tcp'
|
|
66
|
+
// postgres only, useful for Heroku
|
|
67
|
+
protocol: val.protocol || null,
|
|
68
|
+
// disable logging or provide a custom logging function; default: console.log
|
|
69
|
+
logging: val.logging || false,
|
|
70
|
+
|
|
71
|
+
// you can also pass any dialect options to the underlying dialect library
|
|
72
|
+
// - default is empty
|
|
73
|
+
// - currently supported: 'mysql', 'postgres', 'mssql'
|
|
74
|
+
dialectOptions: {
|
|
75
|
+
socketPath: ((val.dialectOptions) ? ((val.dialectOptions.socketPath) ? val.dialectOptions.socketPath : "") : ""), //Applications/MAMP/tmp/mysql/mysql.sock
|
|
76
|
+
supportBigNumbers: ((val.dialectOptions) ? ((val.dialectOptions.supportBigNumbers) ? val.dialectOptions.supportBigNumbers : false) : false),
|
|
77
|
+
bigNumberStrings: ((val.dialectOptions) ? ((val.dialectOptions.bigNumberStrings) ? val.dialectOptions.bigNumberStrings : false) : false),
|
|
78
|
+
options: ((val.dialectOptions) ? ((val.dialectOptions.options) ? ({ encrypt: false, ...val.dialectOptions.options }) : { encrypt: false }) : { encrypt: false }),
|
|
79
|
+
},
|
|
80
|
+
|
|
81
|
+
// disable inserting undefined values as NULL
|
|
82
|
+
// - default: false
|
|
83
|
+
omitNull: val.omitNull || false,
|
|
84
|
+
|
|
85
|
+
// a flag for using a native library or not.
|
|
86
|
+
// in the case of 'pg' -- set this to true will allow SSL support
|
|
87
|
+
// - default: false
|
|
88
|
+
native: val.native || false,
|
|
89
|
+
|
|
90
|
+
// Specify options, which are used when sequelize.define is called.
|
|
91
|
+
// The following example:
|
|
92
|
+
// define: { timestamps: false }
|
|
93
|
+
// is basically the same as:
|
|
94
|
+
// Model.init(attributes, { timestamps: false });
|
|
95
|
+
// sequelize.define(name, attributes, { timestamps: false });
|
|
96
|
+
// so defining the timestamps for each model will be not necessary
|
|
97
|
+
define: {
|
|
98
|
+
underscored: ((val.define) ? ((val.define.underscored) ? val.define.underscored : false) : false),
|
|
99
|
+
freezeTableName: ((val.define) ? ((val.define.freezeTableName === false) ? val.define.freezeTableName : true) : true),
|
|
100
|
+
charset: ((val.define) ? ((val.define.charset) ? val.define.charset : "utf8") : "utf8"),
|
|
101
|
+
dialectOptions: {
|
|
102
|
+
collate: ((val.define) ? ((val.define.dialectOptions) ? ((val.define.dialectOptions.timestamps) ? val.define.dialectOptions.timestamps : "utf8_general_ci") : "utf8_general_ci") : "utf8_general_ci"),
|
|
103
|
+
},
|
|
104
|
+
timestamps: ((val.define) ? ((val.define.timestamps) ? val.define.timestamps : false) : false),
|
|
105
|
+
},
|
|
106
|
+
|
|
107
|
+
// similar for sync: you can define this to always force sync for models
|
|
108
|
+
sync: {
|
|
109
|
+
force: ((val.sync) ? ((val.sync.force) ? val.sync.force : false) : false),
|
|
110
|
+
},
|
|
111
|
+
|
|
112
|
+
// pool configuration used to pool database connections
|
|
113
|
+
pool: {
|
|
114
|
+
max: ((val.pool) ? ((val.pool.max) ? val.pool.max : 5) : 5),
|
|
115
|
+
idle: ((val.pool) ? ((val.pool.idle) ? val.pool.idle : 30000) : 30000),
|
|
116
|
+
acquire: ((val.pool) ? ((val.pool.acquire) ? val.pool.acquire : 60000) : 60000),
|
|
117
|
+
},
|
|
118
|
+
|
|
119
|
+
// isolation level of each transaction
|
|
120
|
+
// defaults to dialect default
|
|
121
|
+
isolationLevel: val.isolationLevel || "Transaction.ISOLATION_LEVELS.REPEATABLE_READ",
|
|
122
|
+
|
|
123
|
+
// JSON response
|
|
124
|
+
query: {
|
|
125
|
+
raw: ((val.query) ? ((val.query.raw) ? val.query.raw : true) : true),
|
|
126
|
+
nest: ((val.query) ? ((val.query.nest) ? val.query.nest : true) : true),
|
|
131
127
|
}
|
|
132
|
-
})
|
|
133
|
-
.catch(err => {
|
|
134
|
-
console.error('Unable to connect to the database:', err);
|
|
135
128
|
});
|
|
129
|
+
|
|
130
|
+
// show only one text db connnections
|
|
131
|
+
if (headDbShow) {
|
|
132
|
+
console.log('[102m[90m Passed [0m [0mDatabase is connected at:');
|
|
133
|
+
headDbShow = false;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// checking shout by dialect sql
|
|
137
|
+
if (val.dialect == "sqlite") {
|
|
138
|
+
// shout for sqlite
|
|
139
|
+
console.log('- [91m[' + val.dialect + '] [0m[36m' + val.name + ' [0m->[93m ' + sq.options.storage + '[0m');
|
|
140
|
+
} else {
|
|
141
|
+
// shuout
|
|
142
|
+
console.log('- [91m[' + val.dialect + '] [0m[36m' + val.name + ' [0m->[93m ' + sq.config.database + ':' + sq.config.port + '[0m');
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// connection
|
|
146
|
+
await sq.authenticate()
|
|
147
|
+
.then(() => {
|
|
148
|
+
// create database pool
|
|
149
|
+
sql[ val.name ] = sq;
|
|
150
|
+
// checking recursive database connection
|
|
151
|
+
if (database_config.length > 0) {
|
|
152
|
+
connectInProcess(database_config, headDbShow, e => {
|
|
153
|
+
cb(e, true);
|
|
154
|
+
});
|
|
155
|
+
} else {
|
|
156
|
+
// perfectly recursive
|
|
157
|
+
cb(null, true);
|
|
158
|
+
}
|
|
159
|
+
})
|
|
160
|
+
.catch(err => {
|
|
161
|
+
console.error('Unable to connect to the database:', err);
|
|
162
|
+
});
|
|
163
|
+
});
|
|
136
164
|
} else {
|
|
137
165
|
if (database_config.length > 0) {
|
|
138
166
|
connectInProcess(database_config, headDbShow, e => {
|