corefwnode 3.0.2 → 3.0.4
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.js +40 -40
- package/build.js +266 -266
- package/index.js +240 -240
- package/lib/CfwObject.js +1629 -1626
- package/lib/Decorator.js +322 -322
- package/lib/ErrorCodes.js +111 -111
- package/lib/ErrorControl.js +50 -50
- package/lib/GeneralHandling.js +638 -638
- package/lib/Language.js +139 -139
- package/lib/MySql.js +141 -142
- package/lib/Observer.js +75 -75
- package/lib/Validator.js +536 -536
- package/lib/Wiki.js +409 -409
- package/lib/errors/CoreError.js +11 -11
- package/lib/errors/SQLError.js +125 -125
- package/objects/AclGroups.js +69 -69
- package/objects/AclObjects.js +46 -46
- package/objects/AclPrivilages.js +202 -202
- package/objects/EmailTemplates.js +108 -108
- package/objects/Session.js +317 -317
- package/objects/SiteProps.js +55 -55
- package/objects/TransLang.js +39 -39
- package/objects/Translator.js +345 -345
- package/objects/UserCompanies.js +46 -46
- package/objects/Users.js +409 -409
- package/objects/UsersData.js +85 -85
- package/objects/Wiki.js +425 -425
- package/objects/WikiCategory.js +40 -40
- package/objects/WikiTemplates.js +92 -92
- package/objects/index.js +47 -47
- package/package.json +31 -32
package/lib/Language.js
CHANGED
|
@@ -1,139 +1,139 @@
|
|
|
1
|
-
const GeneralHandling = require('./GeneralHandling.js');
|
|
2
|
-
const Translator = require('../objects/Translator.js');
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Language class
|
|
6
|
-
*
|
|
7
|
-
* module.exports = class providing language methods, translation and language cache filling
|
|
8
|
-
*
|
|
9
|
-
* @author Dario Filkovic <dfilkovi@gmail.com>
|
|
10
|
-
*
|
|
11
|
-
* @since 1.0
|
|
12
|
-
*
|
|
13
|
-
* @package CoreFw
|
|
14
|
-
*/
|
|
15
|
-
module.exports = class Language
|
|
16
|
-
{
|
|
17
|
-
/**
|
|
18
|
-
* constructor()
|
|
19
|
-
*
|
|
20
|
-
* Constructor initializing Translator object, Cache and filling language variables
|
|
21
|
-
*
|
|
22
|
-
* @author Dario Filkovic <dfilkovi@gmail.com>
|
|
23
|
-
*
|
|
24
|
-
* @since 1.0
|
|
25
|
-
*
|
|
26
|
-
* @package CoreFw
|
|
27
|
-
*
|
|
28
|
-
*/
|
|
29
|
-
constructor()
|
|
30
|
-
{
|
|
31
|
-
const me = this;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Translator object
|
|
35
|
-
* @type Translator
|
|
36
|
-
*/
|
|
37
|
-
me.transObj = new Translator();
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* fillTrans()
|
|
42
|
-
*
|
|
43
|
-
* Check cache for translation, if it doesn't exist, ask Translator object for translation and fill Cache
|
|
44
|
-
*
|
|
45
|
-
* @author Dario Filkovic <dfilkovi@gmail.com>
|
|
46
|
-
*
|
|
47
|
-
* @since 1.0
|
|
48
|
-
*
|
|
49
|
-
* @package CoreFw
|
|
50
|
-
*
|
|
51
|
-
* @return void
|
|
52
|
-
*/
|
|
53
|
-
async fillTrans()
|
|
54
|
-
{
|
|
55
|
-
const me = this;
|
|
56
|
-
|
|
57
|
-
me.trans = await me.transObj.getTranslation();
|
|
58
|
-
|
|
59
|
-
const data = await me.transObj.getLangDefs();
|
|
60
|
-
me.langDefs = data.langDefs;
|
|
61
|
-
me.langCodes = data.langCodes;
|
|
62
|
-
|
|
63
|
-
return { error: false, notice: 'Success' };
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* translate()
|
|
68
|
-
*
|
|
69
|
-
* Translate variable by key, if key was not found check translation
|
|
70
|
-
*
|
|
71
|
-
* @author Dario Filkovic <dfilkovi@gmail.com>
|
|
72
|
-
*
|
|
73
|
-
* @since 1.0
|
|
74
|
-
*
|
|
75
|
-
* @package CoreFw
|
|
76
|
-
*
|
|
77
|
-
* @param String $key Key for translating
|
|
78
|
-
* @return String Returns translated key
|
|
79
|
-
*/
|
|
80
|
-
translate(keyIn, langId)
|
|
81
|
-
{
|
|
82
|
-
const me = this;
|
|
83
|
-
const key = GeneralHandling.safeTrans(keyIn);
|
|
84
|
-
if (typeof me.trans[langId] !== 'undefined' && typeof me.trans[langId][key] !== 'undefined')
|
|
85
|
-
{
|
|
86
|
-
if (me.trans[langId][key] === '')
|
|
87
|
-
{
|
|
88
|
-
return `#${key}`;
|
|
89
|
-
}
|
|
90
|
-
return me.trans[langId][key];
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (key === '')
|
|
94
|
-
{
|
|
95
|
-
return '#EMPTYKEY';
|
|
96
|
-
}
|
|
97
|
-
me.checkTrans(key);
|
|
98
|
-
return `#${key}`;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* _()
|
|
103
|
-
*
|
|
104
|
-
* @see translate
|
|
105
|
-
*
|
|
106
|
-
* @since 1.0
|
|
107
|
-
*
|
|
108
|
-
* @package CoreFw
|
|
109
|
-
*
|
|
110
|
-
* @param String $key Key for translating
|
|
111
|
-
* @return String Returns translated key
|
|
112
|
-
*/
|
|
113
|
-
_(key)
|
|
114
|
-
{
|
|
115
|
-
return this.translate(key);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* checkTrans()
|
|
120
|
-
*
|
|
121
|
-
* Check translation in Translator object,
|
|
122
|
-
* Translator object should handle insertion to database if key is untranslated
|
|
123
|
-
*
|
|
124
|
-
* @author Dario Filkovic <dfilkovi@gmail.com>
|
|
125
|
-
*
|
|
126
|
-
* @since 1.0
|
|
127
|
-
*
|
|
128
|
-
* @package CoreFw
|
|
129
|
-
*
|
|
130
|
-
* @param mixed[] $key Translation key
|
|
131
|
-
* @return void
|
|
132
|
-
*/
|
|
133
|
-
checkTrans(keyIn)
|
|
134
|
-
{
|
|
135
|
-
const me = this;
|
|
136
|
-
const key = GeneralHandling.safeTrans(keyIn);
|
|
137
|
-
me.transObj.checkTrans({ key });
|
|
138
|
-
}
|
|
139
|
-
};
|
|
1
|
+
const GeneralHandling = require('./GeneralHandling.js');
|
|
2
|
+
const Translator = require('../objects/Translator.js');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Language class
|
|
6
|
+
*
|
|
7
|
+
* module.exports = class providing language methods, translation and language cache filling
|
|
8
|
+
*
|
|
9
|
+
* @author Dario Filkovic <dfilkovi@gmail.com>
|
|
10
|
+
*
|
|
11
|
+
* @since 1.0
|
|
12
|
+
*
|
|
13
|
+
* @package CoreFw
|
|
14
|
+
*/
|
|
15
|
+
module.exports = class Language
|
|
16
|
+
{
|
|
17
|
+
/**
|
|
18
|
+
* constructor()
|
|
19
|
+
*
|
|
20
|
+
* Constructor initializing Translator object, Cache and filling language variables
|
|
21
|
+
*
|
|
22
|
+
* @author Dario Filkovic <dfilkovi@gmail.com>
|
|
23
|
+
*
|
|
24
|
+
* @since 1.0
|
|
25
|
+
*
|
|
26
|
+
* @package CoreFw
|
|
27
|
+
*
|
|
28
|
+
*/
|
|
29
|
+
constructor()
|
|
30
|
+
{
|
|
31
|
+
const me = this;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Translator object
|
|
35
|
+
* @type Translator
|
|
36
|
+
*/
|
|
37
|
+
me.transObj = new Translator();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* fillTrans()
|
|
42
|
+
*
|
|
43
|
+
* Check cache for translation, if it doesn't exist, ask Translator object for translation and fill Cache
|
|
44
|
+
*
|
|
45
|
+
* @author Dario Filkovic <dfilkovi@gmail.com>
|
|
46
|
+
*
|
|
47
|
+
* @since 1.0
|
|
48
|
+
*
|
|
49
|
+
* @package CoreFw
|
|
50
|
+
*
|
|
51
|
+
* @return void
|
|
52
|
+
*/
|
|
53
|
+
async fillTrans()
|
|
54
|
+
{
|
|
55
|
+
const me = this;
|
|
56
|
+
|
|
57
|
+
me.trans = await me.transObj.getTranslation();
|
|
58
|
+
|
|
59
|
+
const data = await me.transObj.getLangDefs();
|
|
60
|
+
me.langDefs = data.langDefs;
|
|
61
|
+
me.langCodes = data.langCodes;
|
|
62
|
+
|
|
63
|
+
return { error: false, notice: 'Success' };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* translate()
|
|
68
|
+
*
|
|
69
|
+
* Translate variable by key, if key was not found check translation
|
|
70
|
+
*
|
|
71
|
+
* @author Dario Filkovic <dfilkovi@gmail.com>
|
|
72
|
+
*
|
|
73
|
+
* @since 1.0
|
|
74
|
+
*
|
|
75
|
+
* @package CoreFw
|
|
76
|
+
*
|
|
77
|
+
* @param String $key Key for translating
|
|
78
|
+
* @return String Returns translated key
|
|
79
|
+
*/
|
|
80
|
+
translate(keyIn, langId)
|
|
81
|
+
{
|
|
82
|
+
const me = this;
|
|
83
|
+
const key = GeneralHandling.safeTrans(keyIn);
|
|
84
|
+
if (typeof me.trans[langId] !== 'undefined' && typeof me.trans[langId][key] !== 'undefined')
|
|
85
|
+
{
|
|
86
|
+
if (me.trans[langId][key] === '')
|
|
87
|
+
{
|
|
88
|
+
return `#${key}`;
|
|
89
|
+
}
|
|
90
|
+
return me.trans[langId][key];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (key === '')
|
|
94
|
+
{
|
|
95
|
+
return '#EMPTYKEY';
|
|
96
|
+
}
|
|
97
|
+
me.checkTrans(key);
|
|
98
|
+
return `#${key}`;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* _()
|
|
103
|
+
*
|
|
104
|
+
* @see translate
|
|
105
|
+
*
|
|
106
|
+
* @since 1.0
|
|
107
|
+
*
|
|
108
|
+
* @package CoreFw
|
|
109
|
+
*
|
|
110
|
+
* @param String $key Key for translating
|
|
111
|
+
* @return String Returns translated key
|
|
112
|
+
*/
|
|
113
|
+
_(key)
|
|
114
|
+
{
|
|
115
|
+
return this.translate(key);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* checkTrans()
|
|
120
|
+
*
|
|
121
|
+
* Check translation in Translator object,
|
|
122
|
+
* Translator object should handle insertion to database if key is untranslated
|
|
123
|
+
*
|
|
124
|
+
* @author Dario Filkovic <dfilkovi@gmail.com>
|
|
125
|
+
*
|
|
126
|
+
* @since 1.0
|
|
127
|
+
*
|
|
128
|
+
* @package CoreFw
|
|
129
|
+
*
|
|
130
|
+
* @param mixed[] $key Translation key
|
|
131
|
+
* @return void
|
|
132
|
+
*/
|
|
133
|
+
checkTrans(keyIn)
|
|
134
|
+
{
|
|
135
|
+
const me = this;
|
|
136
|
+
const key = GeneralHandling.safeTrans(keyIn);
|
|
137
|
+
me.transObj.checkTrans({ key });
|
|
138
|
+
}
|
|
139
|
+
};
|
package/lib/MySql.js
CHANGED
|
@@ -1,142 +1,141 @@
|
|
|
1
|
-
|
|
2
|
-
const mysql = require('promise
|
|
3
|
-
const SqlString = require('sqlstring');
|
|
4
|
-
const CoreError = require('./errors/CoreError');
|
|
5
|
-
const SQLError = require('./errors/SQLError');
|
|
6
|
-
|
|
7
|
-
module.exports = class MySQLConn
|
|
8
|
-
{
|
|
9
|
-
static async init(config)
|
|
10
|
-
{
|
|
11
|
-
try
|
|
12
|
-
{
|
|
13
|
-
const db = await mysql.createPool(
|
|
14
|
-
{
|
|
15
|
-
connectionLimit: config.connectionLimit,
|
|
16
|
-
host: config.host,
|
|
17
|
-
user: config.username,
|
|
18
|
-
password: config.password,
|
|
19
|
-
database: config.dbname,
|
|
20
|
-
port: config.port,
|
|
21
|
-
dateStrings: true, // if we want dates as strings
|
|
22
|
-
connectTimeout: 20000,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
connection.
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
//
|
|
91
|
-
|
|
92
|
-
connection
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
};
|
|
1
|
+
|
|
2
|
+
const mysql = require('mysql2/promise');
|
|
3
|
+
const SqlString = require('sqlstring');
|
|
4
|
+
const CoreError = require('./errors/CoreError');
|
|
5
|
+
const SQLError = require('./errors/SQLError');
|
|
6
|
+
|
|
7
|
+
module.exports = class MySQLConn
|
|
8
|
+
{
|
|
9
|
+
static async init(config)
|
|
10
|
+
{
|
|
11
|
+
try
|
|
12
|
+
{
|
|
13
|
+
const db = await mysql.createPool(
|
|
14
|
+
{
|
|
15
|
+
connectionLimit: config.connectionLimit,
|
|
16
|
+
host: config.host,
|
|
17
|
+
user: config.username,
|
|
18
|
+
password: config.password,
|
|
19
|
+
database: config.dbname,
|
|
20
|
+
port: config.port,
|
|
21
|
+
dateStrings: true, // if we want dates as strings
|
|
22
|
+
connectTimeout: 20000,
|
|
23
|
+
queryFormat(query, values)
|
|
24
|
+
{
|
|
25
|
+
let data = query;
|
|
26
|
+
if (!values)
|
|
27
|
+
{
|
|
28
|
+
data = query;
|
|
29
|
+
}
|
|
30
|
+
else
|
|
31
|
+
if (query.indexOf('?') !== -1)
|
|
32
|
+
{
|
|
33
|
+
data = SqlString.format(query, values, this.config.stringifyObjects, this.config.timezone);
|
|
34
|
+
}
|
|
35
|
+
else
|
|
36
|
+
{
|
|
37
|
+
data = query.replace(/:(\w+)/g, (txt, key) =>
|
|
38
|
+
{
|
|
39
|
+
if (Object.prototype.hasOwnProperty.call(values, key))
|
|
40
|
+
{
|
|
41
|
+
return this.escape(values[key]);
|
|
42
|
+
}
|
|
43
|
+
return txt;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
console.log(data, `connected as id ${this.threadId}`);
|
|
47
|
+
return data;
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
db.dbname = config.dbname;
|
|
53
|
+
|
|
54
|
+
db.query = async function query(...args)
|
|
55
|
+
{
|
|
56
|
+
const me = this;
|
|
57
|
+
try
|
|
58
|
+
{
|
|
59
|
+
const res = await Object.getPrototypeOf(me).query.call(me, ...args);
|
|
60
|
+
return res[0];
|
|
61
|
+
}
|
|
62
|
+
catch (e)
|
|
63
|
+
{
|
|
64
|
+
throw (new SQLError(e));
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
db.begin = async (session) =>
|
|
69
|
+
{
|
|
70
|
+
if (typeof session === 'undefined')
|
|
71
|
+
{
|
|
72
|
+
throw (new CoreError({
|
|
73
|
+
error: true,
|
|
74
|
+
notice: 'begin excepts session',
|
|
75
|
+
}));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const connection = await db.getConnection();
|
|
79
|
+
|
|
80
|
+
connection.commitInstance = 0;
|
|
81
|
+
|
|
82
|
+
connection.dbname = db.dbname;
|
|
83
|
+
connection.query = db.query;
|
|
84
|
+
|
|
85
|
+
session.tranDb = connection;
|
|
86
|
+
|
|
87
|
+
connection.begin = () =>
|
|
88
|
+
{
|
|
89
|
+
// dummy function, as begin was already called and
|
|
90
|
+
// mysql does not support nested transactions, return existing connection
|
|
91
|
+
connection.commitInstance += 1;
|
|
92
|
+
return connection;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
connection.rollback = async () =>
|
|
96
|
+
{
|
|
97
|
+
if (connection.commitInstance > 0)
|
|
98
|
+
{
|
|
99
|
+
connection.commitInstance -= 1;
|
|
100
|
+
return db;
|
|
101
|
+
}
|
|
102
|
+
await connection.query('ROLLBACK');
|
|
103
|
+
try
|
|
104
|
+
{
|
|
105
|
+
connection.release();
|
|
106
|
+
}
|
|
107
|
+
catch (error)
|
|
108
|
+
{
|
|
109
|
+
// ignore already released connections
|
|
110
|
+
}
|
|
111
|
+
session.tranDb = null;
|
|
112
|
+
return db;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
connection.commit = async () =>
|
|
116
|
+
{
|
|
117
|
+
if (connection.commitInstance > 0)
|
|
118
|
+
{
|
|
119
|
+
connection.commitInstance -= 1;
|
|
120
|
+
return db;
|
|
121
|
+
}
|
|
122
|
+
await connection.query('COMMIT');
|
|
123
|
+
connection.release();
|
|
124
|
+
session.tranDb = null;
|
|
125
|
+
return db;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
await connection.query('START TRANSACTION');
|
|
129
|
+
|
|
130
|
+
return connection;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
return db;
|
|
134
|
+
}
|
|
135
|
+
catch (error)
|
|
136
|
+
{
|
|
137
|
+
console.error(error);
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
};
|