@ti-engine/core 1.2.4 → 1.3.3

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.
@@ -6,38 +6,275 @@
6
6
  * You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
7
7
  */
8
8
 
9
+ const path = require( "node:path" );
9
10
  const _ = require( "lodash" );
10
- const path = require( "path" );
11
- const labels = require( "#labels" );
12
11
  const config = require( "#config" );
13
- const logger = require( '#logger' );
14
- const exceptions = require( '#exceptions' );
12
+ const tools = require( "#tools" );
15
13
 
16
14
  const defaultEmptyLabel = "!!! label not found !!!";
17
15
 
16
+ /**
17
+ * Enum for defining a localization language based on the ISO 639-1 language code.
18
+ *
19
+ * @readonly
20
+ * @enum {string}
21
+ */
22
+ const localizationLanguageEnum = tools.enum( {
23
+ // A:
24
+ ABKHAZIAN: [ "ab", "Abkhazian", "Abkhazian" ],
25
+ AFAR: [ "aa", "Afar", "Afar" ],
26
+ AFRIKAANS: [ "af", "Afrikaans", "Afrikaans" ],
27
+ AKAN: [ "ak", "Akan", "Akan" ],
28
+ ALBANIAN: [ "sq", "Albanian", "Albanian" ],
29
+ AMHARIC: [ "am", "Amharic", "Amharic" ],
30
+ ARABIC: [ "ar", "Arabic", "Arabic" ],
31
+ ARAGONESE: [ "an", "Aragonese", "Aragonese" ],
32
+ ARMENIAN: [ "hy", "Armenian", "Armenian" ],
33
+ ASSAMESE: [ "as", "Assamese", "Assamese" ],
34
+ AVARIC: [ "av", "Avaric", "Avaric" ],
35
+ AVESTAN: [ "ae", "Avestan", "Avestan" ],
36
+ AYMARA: [ "ay", "Aymara", "Aymara" ],
37
+ AZERBAIJANI: [ "az", "Azerbaijani", "Azerbaijani" ],
38
+ // B:
39
+ BAMBARA: [ "bm", "Bambara", "Bambara" ],
40
+ BASHKIR: [ "ba", "Bashkir", "Bashkir" ],
41
+ BASQUE: [ "eu", "Basque", "Basque" ],
42
+ BELARUSIAN: [ "be", "Belarusian", "Belarusian" ],
43
+ BENGALI: [ "bn", "Bengali", "Bengali" ],
44
+ BIHARI_LANGUAGES: [ "bh", "Bihari languages", "Bihari languages" ],
45
+ BISLAMA: [ "bi", "Bislama", "Bislama" ],
46
+ BOSNIAN: [ "bs", "Bosnian", "Bosnian" ],
47
+ BRETON: [ "br", "Breton", "Breton" ],
48
+ BULGARIAN: [ "bg", "Bulgarian", "Bulgarian" ],
49
+ BURMESE: [ "my", "Burmese", "Burmese" ],
50
+ // C:
51
+ CATALAN: [ "ca", "Catalan", "Catalan" ],
52
+ CENTRAL_KHMER: [ "km", "Central Khmer", "Central Khmer" ],
53
+ CHAMORRO: [ "ch", "Chamorro", "Chamorro" ],
54
+ CHECHEN: [ "ce", "Chechen", "Chechen" ],
55
+ CHICHEWA: [ "ny", "Chichewa", "Chichewa" ],
56
+ CHINESE: [ "zh", "Chinese", "Chinese" ],
57
+ CHURCH_SLAVIC: [ "cu", "Church Slavic", "Church Slavic" ],
58
+ CHUVASH: [ "cv", "Chuvash", "Chuvash" ],
59
+ CORNISH: [ "kw", "Cornish", "Cornish" ],
60
+ CORSICAN: [ "co", "Corsican", "Corsican" ],
61
+ CREE: [ "cr", "Cree", "Cree" ],
62
+ CROATIAN: [ "hr", "Croatian", "Croatian" ],
63
+ CZECH: [ "cs", "Czech", "Czech" ],
64
+ // D:
65
+ DANISH: [ "da", "Danish", "Danish" ],
66
+ DIVEHI: [ "dv", "Divehi", "Divehi" ],
67
+ DUTCH: [ "nl", "Dutch", "Dutch" ],
68
+ DZONGKHA: [ "dz", "Dzongkha", "Dzongkha" ],
69
+ // E:
70
+ ENGLISH: [ "en", "English", "English" ],
71
+ ESPERANTO: [ "eo", "Esperanto", "Esperanto" ],
72
+ ESTONIAN: [ "et", "Estonian", "Estonian" ],
73
+ EWE: [ "ee", "Ewe", "Ewe" ],
74
+ // F:
75
+ FAROESE: [ "fo", "Faroese", "Faroese" ],
76
+ FIJIAN: [ "fj", "Fijian", "Fijian" ],
77
+ FINNISH: [ "fi", "Finnish", "Finnish" ],
78
+ FRENCH: [ "fr", "French", "French" ],
79
+ FULAH: [ "ff", "Fulah", "Fulah" ],
80
+ FRISIAN_WESTERN: [ "fy", "Western Frisian", "Western Frisian" ],
81
+ // G:
82
+ GAELIC_SCOTTISH: [ "gd", "Scottish Gaelic", "Scottish Gaelic" ],
83
+ GALICIAN: [ "gl", "Galician", "Galician" ],
84
+ GANDA: [ "lg", "Ganda", "Ganda" ],
85
+ GEORGIAN: [ "ka", "Georgian", "Georgian" ],
86
+ GERMAN: [ "de", "German", "German" ],
87
+ GREEK_MODERN: [ "el", "Greek, Modern (1453–)", "Greek, Modern (1453–)" ],
88
+ GUARANI: [ "gn", "Guarani", "Guarani" ],
89
+ GUJARATI: [ "gu", "Gujarati", "Gujarati" ],
90
+ // H:
91
+ HAITIAN: [ "ht", "Haitian", "Haitian" ],
92
+ HAUSA: [ "ha", "Hausa", "Hausa" ],
93
+ HEBREW: [ "he", "Hebrew", "Hebrew" ],
94
+ HERERO: [ "hz", "Herero", "Herero" ],
95
+ HINDI: [ "hi", "Hindi", "Hindi" ],
96
+ HIRI_MOTU: [ "ho", "Hiri Motu", "Hiri Motu" ],
97
+ HUNGARIAN: [ "hu", "Hungarian", "Hungarian" ],
98
+ // I:
99
+ ICELANDIC: [ "is", "Icelandic", "Icelandic" ],
100
+ IDO: [ "io", "Ido", "Ido" ],
101
+ IGBO: [ "ig", "Igbo", "Igbo" ],
102
+ INTERLINGUA: [ "ia", "Interlingua", "Interlingua" ],
103
+ INTERLINGUE: [ "ie", "Interlingue", "Interlingue" ],
104
+ INDONESIAN: [ "id", "Indonesian", "Indonesian" ],
105
+ INUKTITUT: [ "iu", "Inuktitut", "Inuktitut" ],
106
+ INUPIAQ: [ "ik", "Inupiaq", "Inupiaq" ],
107
+ IRISH: [ "ga", "Irish", "Irish" ],
108
+ ITALIAN: [ "it", "Italian", "Italian" ],
109
+ // J:
110
+ JAPANESE: [ "ja", "Japanese", "Japanese" ],
111
+ JAVANESE: [ "jv", "Javanese", "Javanese" ],
112
+ // K:
113
+ KALAALLISUT: [ "kl", "Kalaallisut", "Kalaallisut" ],
114
+ KANNADA: [ "kn", "Kannada", "Kannada" ],
115
+ KASHMIRI: [ "ks", "Kashmiri", "Kashmiri" ],
116
+ KAZAKH: [ "kk", "Kazakh", "Kazakh" ],
117
+ KIKUYU: [ "ki", "Kikuyu", "Kikuyu" ],
118
+ KINYARWANDA: [ "rw", "Kinyarwanda", "Kinyarwanda" ],
119
+ KIRGHIZ: [ "ky", "Kirghiz", "Kirghiz" ],
120
+ KOMI: [ "kv", "Komi", "Komi" ],
121
+ KONGO: [ "kg", "Kongo", "Kongo" ],
122
+ KOREAN: [ "ko", "Korean", "Korean" ],
123
+ KUANYAMA: [ "kj", "Kuanyama", "Kuanyama" ],
124
+ KURDISH: [ "ku", "Kurdish", "Kurdish" ],
125
+ // L:
126
+ LAO: [ "lo", "Lao", "Lao" ],
127
+ LATIN: [ "la", "Latin", "Latin" ],
128
+ LATVIAN: [ "lv", "Latvian", "Latvian" ],
129
+ LIMBURGAN: [ "li", "Limburgan", "Limburgan" ],
130
+ LINGALA: [ "ln", "Lingala", "Lingala" ],
131
+ LITHUANIAN: [ "lt", "Lithuanian", "Lithuanian" ],
132
+ LUBA_KATANGA: [ "lu", "Luba-Katanga", "Luba-Katanga" ],
133
+ LUXEMBOURGISH: [ "lb", "Luxembourgish", "Luxembourgish" ],
134
+ // M:
135
+ MACEDONIAN: [ "mk", "Macedonian", "Macedonian" ],
136
+ MALAGASY: [ "mg", "Malagasy", "Malagasy" ],
137
+ MALAY: [ "ms", "Malay", "Malay" ],
138
+ MALAYALAM: [ "ml", "Malayalam", "Malayalam" ],
139
+ MALTESE: [ "mt", "Maltese", "Maltese" ],
140
+ MANX: [ "gv", "Manx", "Manx" ],
141
+ MAORI: [ "mi", "Maori", "Maori" ],
142
+ MARATHI: [ "mr", "Marathi", "Marathi" ],
143
+ MARSHALLESE: [ "mh", "Marshallese", "Marshallese" ],
144
+ MONGOLIAN: [ "mn", "Mongolian", "Mongolian" ],
145
+ // N:
146
+ NAURU: [ "na", "Nauru", "Nauru" ],
147
+ NAVAJO: [ "nv", "Navajo", "Navajo" ],
148
+ NDEBELE_NORTH: [ "nd", "North Ndebele", "North Ndebele" ],
149
+ NDEBELE_SOUTH: [ "nr", "South Ndebele", "South Ndebele" ],
150
+ NDONGA: [ "ng", "Ndonga", "Ndonga" ],
151
+ NEPALI: [ "ne", "Nepali", "Nepali" ],
152
+ NORTHERN_SAMI: [ "se", "Northern Sami", "Northern Sami" ],
153
+ NORWEGIAN: [ "no", "Norwegian", "Norwegian" ],
154
+ NORWEGIAN_BOKMAL: [ "nb", "Norwegian Bokmål", "Norwegian Bokmål" ],
155
+ NORWEGIAN_NYNORSK: [ "nn", "Norwegian Nynorsk", "Norwegian Nynorsk" ],
156
+ // O:
157
+ OCCITAN: [ "oc", "Occitan", "Occitan" ],
158
+ OJIBWA: [ "oj", "Ojibwa", "Ojibwa" ],
159
+ ORIYA: [ "or", "Oriya", "Oriya" ],
160
+ OROMO: [ "om", "Oromo", "Oromo" ],
161
+ OSSETIAN: [ "os", "Ossetian", "Ossetian" ],
162
+ // P:
163
+ PANJABI: [ "pa", "Panjabi", "Panjabi" ],
164
+ PALI: [ "pi", "Pali", "Pali" ],
165
+ PASHTO: [ "ps", "Pashto", "Pashto" ],
166
+ POLISH: [ "pl", "Polish", "Polish" ],
167
+ PORTUGUESE: [ "pt", "Portuguese", "Portuguese" ],
168
+ // Q:
169
+ QUECHUA: [ "qu", "Quechua", "Quechua" ],
170
+ // R:
171
+ ROMANIAN: [ "ro", "Romanian", "Romanian" ],
172
+ ROMANSH: [ "rm", "Romansh", "Romansh" ],
173
+ RUNDI: [ "rn", "Rundi", "Rundi" ],
174
+ RUSSIAN: [ "ru", "Russian", "Russian" ],
175
+ // S:
176
+ SANGO: [ "sg", "Sango", "Sango" ],
177
+ SANSKRIT: [ "sa", "Sanskrit", "Sanskrit" ],
178
+ SARDINIAN: [ "sc", "Sardinian", "Sardinian" ],
179
+ SERBIAN: [ "sr", "Serbian", "Serbian" ],
180
+ SHONA: [ "sn", "Shona", "Shona" ],
181
+ SINDHI: [ "sd", "Sindhi", "Sindhi" ],
182
+ SINHALA: [ "si", "Sinhala", "Sinhala" ],
183
+ SLOVAK: [ "sk", "Slovak", "Slovak" ],
184
+ SLOVENIAN: [ "sl", "Slovenian", "Slovenian" ],
185
+ SOMALI: [ "so", "Somali", "Somali" ],
186
+ SOTHO_SOUTHERN: [ "st", "Southern Sotho", "Southern Sotho" ],
187
+ SPANISH: [ "es", "Spanish", "Spanish" ],
188
+ SUNDANESE: [ "su", "Sundanese", "Sundanese" ],
189
+ SWAHILI: [ "sw", "Swahili", "Swahili" ],
190
+ SWATI: [ "ss", "Swati", "Swati" ],
191
+ SWEDISH: [ "sv", "Swedish", "Swedish" ],
192
+ // T:
193
+ TAGALOG: [ "tl", "Tagalog", "Tagalog" ],
194
+ TAHITIAN: [ "ty", "Tahitian", "Tahitian" ],
195
+ TAJIK: [ "tg", "Tajik", "Tajik" ],
196
+ TAMIL: [ "ta", "Tamil", "Tamil" ],
197
+ TATAR: [ "tt", "Tatar", "Tatar" ],
198
+ TELUGU: [ "te", "Telugu", "Telugu" ],
199
+ THAI: [ "th", "Thai", "Thai" ],
200
+ TIBETAN: [ "bo", "Tibetan", "Tibetan" ],
201
+ TIGRINYA: [ "ti", "Tigrinya", "Tigrinya" ],
202
+ TONGA: [ "to", "Tonga", "Tonga" ],
203
+ TSONGA: [ "ts", "Tsonga", "Tsonga" ],
204
+ TSWANA: [ "tn", "Tswana", "Tswana" ],
205
+ TURKISH: [ "tr", "Turkish", "Turkish" ],
206
+ TURKMEN: [ "tk", "Turkmen", "Turkmen" ],
207
+ TWI: [ "tw", "Twi", "Twi" ],
208
+ // U:
209
+ UIGHUR: [ "ug", "Uighur", "Uighur" ],
210
+ UKRAINIAN: [ "uk", "Ukrainian", "Ukrainian" ],
211
+ URDU: [ "ur", "Urdu", "Urdu" ],
212
+ UZBEK: [ "uz", "Uzbek", "Uzbek" ],
213
+ // V:
214
+ VENDA: [ "ve", "Venda", "Venda" ],
215
+ VIETNAMESE: [ "vi", "Vietnamese", "Vietnamese" ],
216
+ VOLAPUK: [ "vo", "Volapük", "Volapük" ],
217
+ // W:
218
+ WALLON: [ "wa", "Walloon", "Walloon" ],
219
+ WELSH: [ "cy", "Welsh", "Welsh" ],
220
+ WOLOF: [ "wo", "Wolof", "Wolof" ],
221
+ // X:
222
+ XHOSA: [ "xh", "Xhosa", "Xhosa" ],
223
+ // Y:
224
+ YIDDISH: [ "yi", "Yiddish", "Yiddish" ],
225
+ YORUBA: [ "yo", "Yoruba", "Yoruba" ],
226
+ // Z:
227
+ ZHUANG: [ "za", "Zhuang", "Zhuang" ],
228
+ ZULU: [ "zu", "Zulu", "Zulu" ]
229
+ } );
230
+
231
+ /**
232
+ * @typedef {string} TiLocalizationLanguage
233
+ */
234
+ module.exports.localizationLanguage = localizationLanguageEnum;
235
+
236
+ /**
237
+ * The key of this object is the language code, and the value is the textual representation of the label.
238
+ *
239
+ * @typedef {Object<TiLocalizationLanguage, string>} TiLocalizedLabel
240
+ */
241
+
242
+ /**
243
+ * A nested labels tree where intermediate nodes are objects and leaf nodes are language-to-text maps.
244
+ *
245
+ * @typedef {Object<string, TiLocalizedLabel | TiLabelsTree>} TiLabelsTree
246
+ */
247
+
248
+ /**
249
+ * @typedef {Object} TiLabels
250
+ * @property {TiLabelsTree} labels
251
+ */
252
+
253
+ /** @type {TiLabels} */
254
+ const labels = require( "#labels" );
255
+
18
256
  // Load any custom labels defined in the configuration:
19
- try {
20
- const labelsPaths = config.getSetting( config.setting.LOCALIZATION_LABELS_PATH );
257
+ const labelsPaths = config.getSetting( config.setting.LOCALIZATION_LABELS_PATH );
258
+ if ( labelsPaths && _.isArray( labelsPaths ) && labelsPaths.length > 0 ) {
21
259
  _.forEach( labelsPaths, ( labelsPath ) => {
22
260
  let filePath = path.normalize( path.join( process.cwd(), labelsPath ) );
23
261
  let fileLabels = require( filePath );
24
262
  _.merge( labels, fileLabels );
25
263
  } );
26
- } catch ( error ) {
27
- logger.log( `Error while trying to load custom labels.`, logger.logSeverity.ERROR, exceptions.raise( error ) );
28
264
  }
29
265
 
30
- // Prevent further modifications to the labels object:
266
+ // Prevent further modifications to the TiLabels object:
31
267
  Object.freeze( labels );
32
268
 
33
269
  /**
34
- * Used to return the textual value for a label based on the current system language.
270
+ * Used to return the textual value for a label based on the current system language by default or the specified language code if provided.
35
271
  *
36
272
  * @method
37
273
  * @param {string} label This should be a dot-separated JSON path string.
274
+ * @param {TiLocalizationLanguage} [language] The language code to use for the lookup. If not provided, the current system language will be used.
38
275
  * @returns {string}
39
276
  * @public
40
277
  */
41
- module.exports.getLabel = ( label ) => {
42
- return _.get( labels, label + "." + config.getSetting( config.setting.LOCALIZATION_LANGUAGE ), defaultEmptyLabel );
278
+ module.exports.getLabel = ( label, language ) => {
279
+ return _.get( labels, label + "." + ( ( language ) ? language : config.getSetting( config.setting.LOCALIZATION_LANGUAGE ) ), defaultEmptyLabel );
43
280
  };
package/utils/logger.js CHANGED
@@ -17,7 +17,7 @@ const localization = require( "#localization" );
17
17
  * @readonly
18
18
  * @enum {number}
19
19
  */
20
- let logSeverityEnum = tools.enum( {
20
+ const logSeverityEnum = tools.enum( {
21
21
  DEFAULT: [ 0, "default", "The log entry has no assigned severity level." ],
22
22
  DEBUG: [ 100, "debug", "Debug or trace information." ],
23
23
  INFO: [ 200, "info", "Routine information, such as ongoing status or performance." ],
@@ -46,7 +46,7 @@ module.exports.getSeverityName = ( severity ) => {
46
46
  };
47
47
 
48
48
  /**
49
- * Used to extract information from an Exception and convert it to loggable data object.
49
+ * Used to extract information from an Exception and convert it to a loggable data object.
50
50
  *
51
51
  * @method
52
52
  * @param {Exception} exception
@@ -62,7 +62,7 @@ const exceptionToLog = ( exception ) => {
62
62
  };
63
63
 
64
64
  /**
65
- * Used to generate and store a log entry in the active cache.
65
+ * Used to generate and store a new log entry via the active {@link Auditing} instance.
66
66
  *
67
67
  * @method
68
68
  * @param {string} message The primary log message.
package/utils/tools.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  * The ti-engine is an open source, free to use—both for personal and commercial projects—framework for the creation of microservice-based solutions using node.js.
3
- * Copyright © 2021-2023 Boris Kostadinov <kostadinov.boris@gmail.com>
3
+ * Copyright © 2021-2025 Boris Kostadinov <kostadinov.boris@gmail.com>
4
4
  * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
5
5
  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
6
6
  * You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
@@ -8,7 +8,7 @@
8
8
 
9
9
  const _ = require( "lodash" );
10
10
  const fs = require( "fs-extra" );
11
- const crypto = require( "crypto" );
11
+ const crypto = require( "node:crypto" );
12
12
 
13
13
  /**
14
14
  * @typedef {Object} TiEnumValue