tiny-essentials 1.0.0
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/.github/FUNDING.yml +4 -0
- package/.github/workflows/node.js.yml +31 -0
- package/LICENSE +674 -0
- package/README.md +67 -0
- package/dist/TinyEssentials.min.js +1 -0
- package/dist/_virtual/_commonjsHelpers.cjs +7 -0
- package/dist/_virtual/common.cjs +5 -0
- package/dist/_virtual/index.cjs +9 -0
- package/dist/_virtual/index2.cjs +5 -0
- package/dist/_virtual/trace.cjs +5 -0
- package/dist/legacy/crypto/decrypt.cjs +57 -0
- package/dist/legacy/crypto/decrypt.d.mts +18 -0
- package/dist/legacy/crypto/decrypt.mjs +47 -0
- package/dist/legacy/crypto/default.cjs +23 -0
- package/dist/legacy/crypto/default.d.mts +35 -0
- package/dist/legacy/crypto/default.mjs +19 -0
- package/dist/legacy/crypto/encrypt.cjs +54 -0
- package/dist/legacy/crypto/encrypt.d.mts +19 -0
- package/dist/legacy/crypto/encrypt.mjs +46 -0
- package/dist/legacy/crypto/index.cjs +11 -0
- package/dist/legacy/crypto/index.d.mts +4 -0
- package/dist/legacy/crypto/index.mjs +6 -0
- package/dist/legacy/firebase/cookieSession.cjs +121 -0
- package/dist/legacy/firebase/cookieSession.d.mts +56 -0
- package/dist/legacy/firebase/cookieSession.mjs +114 -0
- package/dist/legacy/firebase/database/index.cjs +11 -0
- package/dist/legacy/firebase/database/index.d.mts +7 -0
- package/dist/legacy/firebase/database/index.mjs +7 -0
- package/dist/legacy/firebase/database/presence.cjs +131 -0
- package/dist/legacy/firebase/database/presence.d.mts +9 -0
- package/dist/legacy/firebase/database/presence.mjs +111 -0
- package/dist/legacy/firebase/database/saveAsync.cjs +147 -0
- package/dist/legacy/firebase/database/saveAsync.d.mts +54 -0
- package/dist/legacy/firebase/database/saveAsync.mjs +147 -0
- package/dist/legacy/firebase/databaseEscape.cjs +42 -0
- package/dist/legacy/firebase/databaseEscape.d.mts +11 -0
- package/dist/legacy/firebase/databaseEscape.mjs +37 -0
- package/dist/legacy/firebase/databaseLogger.cjs +258 -0
- package/dist/legacy/firebase/databaseLogger.d.mts +7 -0
- package/dist/legacy/firebase/databaseLogger.mjs +234 -0
- package/dist/legacy/firebase/discord/api/addGuildMember.cjs +71 -0
- package/dist/legacy/firebase/discord/api/addGuildMember.d.mts +38 -0
- package/dist/legacy/firebase/discord/api/addGuildMember.mjs +64 -0
- package/dist/legacy/firebase/discord/api/getGuildWidget.cjs +47 -0
- package/dist/legacy/firebase/discord/api/getGuildWidget.d.mts +17 -0
- package/dist/legacy/firebase/discord/api/getGuildWidget.mjs +43 -0
- package/dist/legacy/firebase/discord/api/getToken.cjs +67 -0
- package/dist/legacy/firebase/discord/api/getToken.d.mts +35 -0
- package/dist/legacy/firebase/discord/api/getToken.mjs +63 -0
- package/dist/legacy/firebase/discord/api/getUser.cjs +58 -0
- package/dist/legacy/firebase/discord/api/getUser.d.mts +27 -0
- package/dist/legacy/firebase/discord/api/getUser.mjs +54 -0
- package/dist/legacy/firebase/discord/api/getUserConnections.cjs +57 -0
- package/dist/legacy/firebase/discord/api/getUserConnections.d.mts +26 -0
- package/dist/legacy/firebase/discord/api/getUserConnections.mjs +53 -0
- package/dist/legacy/firebase/discord/api/getUserGuilds.cjs +56 -0
- package/dist/legacy/firebase/discord/api/getUserGuilds.d.mts +25 -0
- package/dist/legacy/firebase/discord/api/getUserGuilds.mjs +52 -0
- package/dist/legacy/firebase/discord/api/index.cjs +24 -0
- package/dist/legacy/firebase/discord/api/index.d.mts +19 -0
- package/dist/legacy/firebase/discord/api/index.mjs +20 -0
- package/dist/legacy/firebase/discord/api/refreshToken.cjs +77 -0
- package/dist/legacy/firebase/discord/api/refreshToken.d.mts +45 -0
- package/dist/legacy/firebase/discord/api/refreshToken.mjs +73 -0
- package/dist/legacy/firebase/discord/api/revokeToken.cjs +61 -0
- package/dist/legacy/firebase/discord/api/revokeToken.d.mts +29 -0
- package/dist/legacy/firebase/discord/api/revokeToken.mjs +58 -0
- package/dist/legacy/firebase/discord/config.cjs +21 -0
- package/dist/legacy/firebase/discord/config.d.mts +27 -0
- package/dist/legacy/firebase/discord/config.mjs +17 -0
- package/dist/legacy/firebase/discord/firebase_redirect/index.cjs +11 -0
- package/dist/legacy/firebase/discord/firebase_redirect/index.d.mts +7 -0
- package/dist/legacy/firebase/discord/firebase_redirect/index.mjs +7 -0
- package/dist/legacy/firebase/discord/firebase_redirect/login.cjs +110 -0
- package/dist/legacy/firebase/discord/firebase_redirect/login.d.mts +4 -0
- package/dist/legacy/firebase/discord/firebase_redirect/login.mjs +107 -0
- package/dist/legacy/firebase/discord/firebase_redirect/logout.cjs +100 -0
- package/dist/legacy/firebase/discord/firebase_redirect/logout.d.mts +4 -0
- package/dist/legacy/firebase/discord/firebase_redirect/logout.mjs +97 -0
- package/dist/legacy/firebase/discord/get/authURLGenerator.cjs +76 -0
- package/dist/legacy/firebase/discord/get/authURLGenerator.d.mts +23 -0
- package/dist/legacy/firebase/discord/get/authURLGenerator.mjs +67 -0
- package/dist/legacy/firebase/discord/get/cookie-session.cjs +32 -0
- package/dist/legacy/firebase/discord/get/cookie-session.d.mts +20 -0
- package/dist/legacy/firebase/discord/get/cookie-session.mjs +28 -0
- package/dist/legacy/firebase/discord/get/credentials.cjs +24 -0
- package/dist/legacy/firebase/discord/get/credentials.d.mts +19 -0
- package/dist/legacy/firebase/discord/get/credentials.mjs +20 -0
- package/dist/legacy/firebase/discord/get/errorValidator.cjs +60 -0
- package/dist/legacy/firebase/discord/get/errorValidator.d.mts +28 -0
- package/dist/legacy/firebase/discord/get/errorValidator.mjs +55 -0
- package/dist/legacy/firebase/discord/get/index.cjs +17 -0
- package/dist/legacy/firebase/discord/get/index.d.mts +13 -0
- package/dist/legacy/firebase/discord/get/index.mjs +13 -0
- package/dist/legacy/firebase/discord/get/randomAvatar.cjs +37 -0
- package/dist/legacy/firebase/discord/get/randomAvatar.d.mts +22 -0
- package/dist/legacy/firebase/discord/get/randomAvatar.mjs +30 -0
- package/dist/legacy/firebase/discord/http/index.cjs +15 -0
- package/dist/legacy/firebase/discord/http/index.d.mts +11 -0
- package/dist/legacy/firebase/discord/http/index.mjs +11 -0
- package/dist/legacy/firebase/discord/http/login.cjs +127 -0
- package/dist/legacy/firebase/discord/http/login.d.mts +21 -0
- package/dist/legacy/firebase/discord/http/login.mjs +123 -0
- package/dist/legacy/firebase/discord/http/logout.cjs +155 -0
- package/dist/legacy/firebase/discord/http/logout.d.mts +22 -0
- package/dist/legacy/firebase/discord/http/logout.mjs +143 -0
- package/dist/legacy/firebase/discord/http/redirect.cjs +188 -0
- package/dist/legacy/firebase/discord/http/redirect.d.mts +24 -0
- package/dist/legacy/firebase/discord/http/redirect.mjs +178 -0
- package/dist/legacy/firebase/discord/http/refreshToken.cjs +133 -0
- package/dist/legacy/firebase/discord/http/refreshToken.d.mts +24 -0
- package/dist/legacy/firebase/discord/http/refreshToken.mjs +121 -0
- package/dist/legacy/firebase/discord/index.cjs +19 -0
- package/dist/legacy/firebase/discord/index.d.mts +15 -0
- package/dist/legacy/firebase/discord/index.mjs +15 -0
- package/dist/legacy/firebase/discord/template/cookie-session.cjs +1430 -0
- package/dist/legacy/firebase/discord/template/cookie-session.d.mts +22 -0
- package/dist/legacy/firebase/discord/template/cookie-session.mjs +1159 -0
- package/dist/legacy/firebase/domainRedirect.cjs +35 -0
- package/dist/legacy/firebase/domainRedirect.d.mts +12 -0
- package/dist/legacy/firebase/domainRedirect.mjs +27 -0
- package/dist/legacy/firebase/escape.cjs +75 -0
- package/dist/legacy/firebase/escape.d.mts +17 -0
- package/dist/legacy/firebase/escape.mjs +58 -0
- package/dist/legacy/firebase/getDBAsync.cjs +33 -0
- package/dist/legacy/firebase/getDBAsync.d.mts +10 -0
- package/dist/legacy/firebase/getDBAsync.mjs +26 -0
- package/dist/legacy/firebase/getDBData.cjs +21 -0
- package/dist/legacy/firebase/getDBData.d.mts +1 -0
- package/dist/legacy/firebase/getDBData.mjs +17 -0
- package/dist/legacy/firebase/getDBValue.cjs +17 -0
- package/dist/legacy/firebase/getDBValue.d.mts +9 -0
- package/dist/legacy/firebase/getDBValue.mjs +14 -0
- package/dist/legacy/firebase/index.cjs +261 -0
- package/dist/legacy/firebase/index.d.mts +51 -0
- package/dist/legacy/firebase/index.mjs +234 -0
- package/dist/legacy/firebase/isEmulator.cjs +14 -0
- package/dist/legacy/firebase/isEmulator.d.mts +8 -0
- package/dist/legacy/firebase/isEmulator.mjs +10 -0
- package/dist/legacy/firebase/logger.cjs +137 -0
- package/dist/legacy/firebase/logger.d.mts +7 -0
- package/dist/legacy/firebase/logger.mjs +125 -0
- package/dist/legacy/firebase/mySQL.cjs +26 -0
- package/dist/legacy/firebase/mySQL.d.mts +10 -0
- package/dist/legacy/firebase/mySQL.mjs +22 -0
- package/dist/legacy/firebase/mysqlConnector/create.cjs +119 -0
- package/dist/legacy/firebase/mysqlConnector/create.d.mts +36 -0
- package/dist/legacy/firebase/mysqlConnector/create.mjs +109 -0
- package/dist/legacy/firebase/mysqlConnector/index.cjs +23 -0
- package/dist/legacy/firebase/mysqlConnector/index.d.mts +11 -0
- package/dist/legacy/firebase/mysqlConnector/index.mjs +16 -0
- package/dist/legacy/firebase/mysqlConnector/nextPrev.cjs +75 -0
- package/dist/legacy/firebase/mysqlConnector/nextPrev.d.mts +31 -0
- package/dist/legacy/firebase/mysqlConnector/nextPrev.mjs +63 -0
- package/dist/legacy/firebase/mysqlConnector/pagination.cjs +91 -0
- package/dist/legacy/firebase/mysqlConnector/pagination.d.mts +33 -0
- package/dist/legacy/firebase/mysqlConnector/pagination.mjs +87 -0
- package/dist/legacy/firebase/mysqlConnector/sameUser.cjs +28 -0
- package/dist/legacy/firebase/mysqlConnector/sameUser.d.mts +12 -0
- package/dist/legacy/firebase/mysqlConnector/sameUser.mjs +23 -0
- package/dist/legacy/firebase/transactionDBAsync.cjs +33 -0
- package/dist/legacy/firebase/transactionDBAsync.d.mts +11 -0
- package/dist/legacy/firebase/transactionDBAsync.mjs +27 -0
- package/dist/legacy/get/countObj.cjs +24 -0
- package/dist/legacy/get/countObj.d.mts +11 -0
- package/dist/legacy/get/countObj.mjs +21 -0
- package/dist/legacy/get/decimalColor.cjs +60 -0
- package/dist/legacy/get/decimalColor.d.mts +12 -0
- package/dist/legacy/get/decimalColor.mjs +54 -0
- package/dist/legacy/get/objType.cjs +43 -0
- package/dist/legacy/get/objType.d.mts +19 -0
- package/dist/legacy/get/objType.mjs +40 -0
- package/dist/legacy/get/pagination.cjs +100 -0
- package/dist/legacy/get/pagination.d.mts +25 -0
- package/dist/legacy/get/pagination.mjs +91 -0
- package/dist/legacy/get/queryUrlByName.cjs +31 -0
- package/dist/legacy/get/queryUrlByName.d.mts +20 -0
- package/dist/legacy/get/queryUrlByName.mjs +28 -0
- package/dist/legacy/get/queryUrlJSON.cjs +54 -0
- package/dist/legacy/get/queryUrlJSON.d.mts +23 -0
- package/dist/legacy/get/queryUrlJSON.mjs +57 -0
- package/dist/legacy/get/super_string_filter.cjs +97 -0
- package/dist/legacy/get/super_string_filter.d.mts +25 -0
- package/dist/legacy/get/super_string_filter.mjs +83 -0
- package/dist/legacy/get/versionCheck.cjs +49 -0
- package/dist/legacy/get/versionCheck.d.mts +17 -0
- package/dist/legacy/get/versionCheck.mjs +38 -0
- package/dist/legacy/http/HTTP-1.0.cjs +151 -0
- package/dist/legacy/http/HTTP-1.0.d.mts +8 -0
- package/dist/legacy/http/HTTP-1.0.mjs +136 -0
- package/dist/legacy/http/auth.cjs +70 -0
- package/dist/legacy/http/auth.d.mts +41 -0
- package/dist/legacy/http/auth.mjs +63 -0
- package/dist/legacy/http/check_domain.cjs +84 -0
- package/dist/legacy/http/check_domain.d.mts +10 -0
- package/dist/legacy/http/check_domain.mjs +82 -0
- package/dist/legacy/http/csrfTokenAnalyze.cjs +46 -0
- package/dist/legacy/http/csrfTokenAnalyze.d.mts +21 -0
- package/dist/legacy/http/csrfTokenAnalyze.mjs +40 -0
- package/dist/legacy/http/domainValidator.cjs +98 -0
- package/dist/legacy/http/domainValidator.d.mts +30 -0
- package/dist/legacy/http/domainValidator.mjs +82 -0
- package/dist/legacy/http/errorsCallback.cjs +55 -0
- package/dist/legacy/http/errorsCallback.d.mts +29 -0
- package/dist/legacy/http/errorsCallback.mjs +48 -0
- package/dist/legacy/http/fetch/json.cjs +48 -0
- package/dist/legacy/http/fetch/json.d.mts +22 -0
- package/dist/legacy/http/fetch/json.mjs +41 -0
- package/dist/legacy/http/fetch/text.cjs +47 -0
- package/dist/legacy/http/fetch/text.d.mts +21 -0
- package/dist/legacy/http/fetch/text.mjs +40 -0
- package/dist/legacy/http/fileCache.cjs +79 -0
- package/dist/legacy/http/fileCache.d.mts +35 -0
- package/dist/legacy/http/fileCache.mjs +70 -0
- package/dist/legacy/http/getDomainURL.cjs +59 -0
- package/dist/legacy/http/getDomainURL.d.mts +18 -0
- package/dist/legacy/http/getDomainURL.mjs +54 -0
- package/dist/legacy/http/userIP.cjs +59 -0
- package/dist/legacy/http/userIP.d.mts +21 -0
- package/dist/legacy/http/userIP.mjs +48 -0
- package/dist/legacy/index.cjs +122 -0
- package/dist/legacy/index.d.mts +89 -0
- package/dist/legacy/index.mjs +92 -0
- package/dist/legacy/libs/arraySortPositions.cjs +30 -0
- package/dist/legacy/libs/arraySortPositions.d.mts +16 -0
- package/dist/legacy/libs/arraySortPositions.mjs +27 -0
- package/dist/legacy/libs/capitalize.cjs +21 -0
- package/dist/legacy/libs/capitalize.d.mts +13 -0
- package/dist/legacy/libs/capitalize.mjs +17 -0
- package/dist/legacy/libs/convertBytes.cjs +64 -0
- package/dist/legacy/libs/convertBytes.d.mts +17 -0
- package/dist/legacy/libs/convertBytes.mjs +55 -0
- package/dist/legacy/libs/custom_module_loader.cjs +82 -0
- package/dist/legacy/libs/custom_module_loader.d.mts +5 -0
- package/dist/legacy/libs/custom_module_loader.mjs +79 -0
- package/dist/legacy/libs/dice.cjs +35 -0
- package/dist/legacy/libs/dice.d.mts +5 -0
- package/dist/legacy/libs/dice.mjs +31 -0
- package/dist/legacy/libs/markdown.cjs +85 -0
- package/dist/legacy/libs/markdown.d.mts +75 -0
- package/dist/legacy/libs/markdown.mjs +78 -0
- package/dist/legacy/libs/percentage.cjs +22 -0
- package/dist/legacy/libs/percentage.d.mts +4 -0
- package/dist/legacy/libs/percentage.mjs +19 -0
- package/dist/legacy/libs/regex/getLetter.cjs +22 -0
- package/dist/legacy/libs/regex/getLetter.d.mts +12 -0
- package/dist/legacy/libs/regex/getLetter.mjs +19 -0
- package/dist/legacy/libs/replaceAsync.cjs +32 -0
- package/dist/legacy/libs/replaceAsync.d.mts +15 -0
- package/dist/legacy/libs/replaceAsync.mjs +25 -0
- package/dist/legacy/libs/rule3.cjs +58 -0
- package/dist/legacy/libs/rule3.d.mts +5 -0
- package/dist/legacy/libs/rule3.mjs +54 -0
- package/dist/legacy/libs/userLevel.cjs +134 -0
- package/dist/legacy/libs/userLevel.d.mts +69 -0
- package/dist/legacy/libs/userLevel.mjs +123 -0
- package/dist/legacy/momentjs/getAge.cjs +28 -0
- package/dist/legacy/momentjs/getAge.d.mts +8 -0
- package/dist/legacy/momentjs/getAge.mjs +22 -0
- package/dist/legacy/momentjs/index.cjs +9 -0
- package/dist/legacy/momentjs/index.d.mts +3 -0
- package/dist/legacy/momentjs/index.mjs +3 -0
- package/dist/legacy/momentjs/timeDuration.cjs +29 -0
- package/dist/legacy/momentjs/timeDuration.d.mts +9 -0
- package/dist/legacy/momentjs/timeDuration.mjs +23 -0
- package/dist/legacy/socket.io/antiFlood/index.cjs +9 -0
- package/dist/legacy/socket.io/antiFlood/index.d.mts +3 -0
- package/dist/legacy/socket.io/antiFlood/index.mjs +3 -0
- package/dist/legacy/socket.io/antiFlood/install.cjs +32 -0
- package/dist/legacy/socket.io/antiFlood/install.d.mts +14 -0
- package/dist/legacy/socket.io/antiFlood/install.mjs +27 -0
- package/dist/legacy/socket.io/antiFlood/verify.cjs +87 -0
- package/dist/legacy/socket.io/antiFlood/verify.d.mts +15 -0
- package/dist/legacy/socket.io/antiFlood/verify.mjs +73 -0
- package/dist/legacy/socket.io/cookie-session.cjs +25 -0
- package/dist/legacy/socket.io/cookie-session.d.mts +9 -0
- package/dist/legacy/socket.io/cookie-session.mjs +20 -0
- package/dist/legacy/socket.io/discord.cjs +61 -0
- package/dist/legacy/socket.io/discord.d.mts +10 -0
- package/dist/legacy/socket.io/discord.mjs +52 -0
- package/dist/legacy/socket.io/index.cjs +13 -0
- package/dist/legacy/socket.io/index.d.mts +9 -0
- package/dist/legacy/socket.io/index.mjs +9 -0
- package/dist/v1/basics/array.cjs +31 -0
- package/dist/v1/basics/array.d.mts +10 -0
- package/dist/v1/basics/array.mjs +22 -0
- package/dist/v1/basics/clock.cjs +187 -0
- package/dist/v1/basics/clock.d.mts +37 -0
- package/dist/v1/basics/clock.mjs +152 -0
- package/dist/v1/basics/objFilter.cjs +55 -0
- package/dist/v1/basics/objFilter.d.mts +27 -0
- package/dist/v1/basics/objFilter.mjs +52 -0
- package/dist/v1/basics/simpleMath.cjs +88 -0
- package/dist/v1/basics/simpleMath.d.mts +54 -0
- package/dist/v1/basics/simpleMath.mjs +75 -0
- package/dist/v1/basics/text.cjs +34 -0
- package/dist/v1/basics/text.d.mts +20 -0
- package/dist/v1/basics/text.mjs +25 -0
- package/dist/v1/index.cjs +26 -0
- package/dist/v1/index.d.mts +15 -0
- package/dist/v1/index.mjs +8 -0
- package/package.json +72 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Class representing an asynchronous save system with callback support.
|
|
3
|
+
*
|
|
4
|
+
* This class is designed to handle database operations asynchronously and supports
|
|
5
|
+
* adding multiple operations to a queue, as well as running callbacks after each action.
|
|
6
|
+
*
|
|
7
|
+
* @class SaveAsync
|
|
8
|
+
*/
|
|
9
|
+
class SaveAsync {
|
|
10
|
+
/**
|
|
11
|
+
* Creates an instance of SaveAsync.
|
|
12
|
+
*
|
|
13
|
+
* @param {object} db - The database reference to interact with (e.g., Firebase or other DB).
|
|
14
|
+
*/
|
|
15
|
+
constructor(db) {
|
|
16
|
+
this.db = db;
|
|
17
|
+
this.list = [];
|
|
18
|
+
this.callbacks = {};
|
|
19
|
+
this.using = false;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Registers a callback to be run when a specific action type is executed.
|
|
23
|
+
*
|
|
24
|
+
* @param {string} where - The action type (e.g., "set", "push", etc.).
|
|
25
|
+
* @param {Function} callback - The callback function to run when the action is performed.
|
|
26
|
+
* @returns {boolean} Returns `true` if the callback is successfully registered.
|
|
27
|
+
*/
|
|
28
|
+
on(where, callback) {
|
|
29
|
+
if (!Array.isArray(this.callbacks[where]))
|
|
30
|
+
this.callbacks[where] = [];
|
|
31
|
+
this.callbacks[where].push(callback);
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Runs all callbacks associated with a specific action type.
|
|
36
|
+
*
|
|
37
|
+
* @param {string} type - The action type (e.g., "set", "push", etc.).
|
|
38
|
+
* @param {any} data - The data passed to the callback(s).
|
|
39
|
+
* @param {string} [where] - The location (optional) where the action was performed.
|
|
40
|
+
*/
|
|
41
|
+
_runCallbacks(type, data, where) {
|
|
42
|
+
if (Array.isArray(this.callbacks[type]))
|
|
43
|
+
for (const item in this.callbacks[type])
|
|
44
|
+
if (typeof this.callbacks[type][item] === 'function')
|
|
45
|
+
this.callbacks[type][item](data, where);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Processes the queued actions and executes them one by one.
|
|
49
|
+
*
|
|
50
|
+
* Each action in the queue is processed asynchronously. Once one action completes,
|
|
51
|
+
* the next action in the queue is triggered.
|
|
52
|
+
*/
|
|
53
|
+
action() {
|
|
54
|
+
// Insert
|
|
55
|
+
if (this.list.length > 0) {
|
|
56
|
+
// Get Item
|
|
57
|
+
const post = this.list.shift();
|
|
58
|
+
const tinyThis = this;
|
|
59
|
+
// Try
|
|
60
|
+
try {
|
|
61
|
+
if (typeof post.where !== 'string') {
|
|
62
|
+
if (post.data) {
|
|
63
|
+
this.db[post.type](post.data)
|
|
64
|
+
.then(() => {
|
|
65
|
+
this._runCallbacks(post.type, post.data);
|
|
66
|
+
tinyThis.action();
|
|
67
|
+
})
|
|
68
|
+
.catch((err) => {
|
|
69
|
+
console.error(err);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
this.db[post.type]()
|
|
74
|
+
.then(() => {
|
|
75
|
+
this._runCallbacks(post.type);
|
|
76
|
+
tinyThis.action();
|
|
77
|
+
})
|
|
78
|
+
.catch((err) => {
|
|
79
|
+
console.error(err);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
if (post.data) {
|
|
85
|
+
this.db
|
|
86
|
+
.child(post.where)[post.type](post.data)
|
|
87
|
+
.then(() => {
|
|
88
|
+
this._runCallbacks(post.type, post.data, post.where);
|
|
89
|
+
tinyThis.action();
|
|
90
|
+
})
|
|
91
|
+
.catch((err) => {
|
|
92
|
+
console.error(err);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
this.db
|
|
97
|
+
.child(post.where)[post.type]()
|
|
98
|
+
.then(() => {
|
|
99
|
+
this._runCallbacks(post.type, null, post.where);
|
|
100
|
+
tinyThis.action();
|
|
101
|
+
})
|
|
102
|
+
.catch((err) => {
|
|
103
|
+
console.error(err);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
catch (err) {
|
|
109
|
+
// Error
|
|
110
|
+
console.error(err);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
// Nope
|
|
114
|
+
else
|
|
115
|
+
this.using = false;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Inserts a new action into the queue.
|
|
119
|
+
*
|
|
120
|
+
* The action will be executed when the system is ready (i.e., when the queue is not in use).
|
|
121
|
+
*
|
|
122
|
+
* @param {object} [data={}] - The data to be saved (optional).
|
|
123
|
+
* @param {string} [type='set'] - The type of the database action (e.g., 'set', 'push', etc.).
|
|
124
|
+
* @param {string|null} [where=null] - The location where the data should be stored (optional).
|
|
125
|
+
*/
|
|
126
|
+
insert(data = {}, type = 'set', where = null) {
|
|
127
|
+
// Insert
|
|
128
|
+
if (data !== null) {
|
|
129
|
+
if (where !== null)
|
|
130
|
+
this.list.push({ where: String(where), data: data, type: type });
|
|
131
|
+
else
|
|
132
|
+
this.list.push({ data: data, type: type });
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
if (where !== null)
|
|
136
|
+
this.list.push({ where: String(where), type: type });
|
|
137
|
+
else
|
|
138
|
+
this.list.push({ type: type });
|
|
139
|
+
}
|
|
140
|
+
if (!this.using) {
|
|
141
|
+
this.using = true;
|
|
142
|
+
this.action();
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
// Module export
|
|
147
|
+
export default SaveAsync;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var escape = require('./escape.cjs');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Escapes a given string or number for use in Firebase database paths, with an option to preserve the path structure.
|
|
7
|
+
*
|
|
8
|
+
* This function encodes the input string or number using a custom encoding defined in the `firebaseEscape.encode()` method.
|
|
9
|
+
* If the `keepPath` flag is set to `true`, the function will encode each segment of the path individually.
|
|
10
|
+
*
|
|
11
|
+
* @param {string|number} text - The text or number to be escaped.
|
|
12
|
+
* @param {boolean} [keepPath=false] - Whether to preserve the path structure (encode each path segment separately).
|
|
13
|
+
* @returns {string|null} The escaped string or null if the input is neither a string nor a number.
|
|
14
|
+
*/
|
|
15
|
+
function databaseEscape(text, keepPath = false) {
|
|
16
|
+
// Check if the input is a string or number
|
|
17
|
+
if (typeof text === 'string' || typeof text === 'number') {
|
|
18
|
+
// Convert the value to a string if it's a number
|
|
19
|
+
let new_value = text;
|
|
20
|
+
if (typeof new_value === 'number') new_value = String(new_value);
|
|
21
|
+
|
|
22
|
+
// Normal escape (do not preserve path)
|
|
23
|
+
if (!keepPath) new_value = escape.encode(new_value);
|
|
24
|
+
// Escape path segments individually (preserve path structure)
|
|
25
|
+
else {
|
|
26
|
+
// Split path into segments
|
|
27
|
+
new_value = new_value.split('/');
|
|
28
|
+
for (const item in new_value) new_value[item] = escape.encode(new_value[item]);
|
|
29
|
+
|
|
30
|
+
// Join the segments back into a single string
|
|
31
|
+
new_value = new_value.join('/');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Return the escaped value
|
|
35
|
+
return new_value;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Return null if the input is neither a string nor a number
|
|
39
|
+
else return null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
module.exports = databaseEscape;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Escapes a given string or number for use in Firebase database paths, with an option to preserve the path structure.
|
|
3
|
+
*
|
|
4
|
+
* This function encodes the input string or number using a custom encoding defined in the `firebaseEscape.encode()` method.
|
|
5
|
+
* If the `keepPath` flag is set to `true`, the function will encode each segment of the path individually.
|
|
6
|
+
*
|
|
7
|
+
* @param {string|number} text - The text or number to be escaped.
|
|
8
|
+
* @param {boolean} [keepPath=false] - Whether to preserve the path structure (encode each path segment separately).
|
|
9
|
+
* @returns {string|null} The escaped string or null if the input is neither a string nor a number.
|
|
10
|
+
*/
|
|
11
|
+
export default function databaseEscape(text: string | number, keepPath?: boolean): string | null;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import * as firebaseEscape from './escape.mjs';
|
|
2
|
+
/**
|
|
3
|
+
* Escapes a given string or number for use in Firebase database paths, with an option to preserve the path structure.
|
|
4
|
+
*
|
|
5
|
+
* This function encodes the input string or number using a custom encoding defined in the `firebaseEscape.encode()` method.
|
|
6
|
+
* If the `keepPath` flag is set to `true`, the function will encode each segment of the path individually.
|
|
7
|
+
*
|
|
8
|
+
* @param {string|number} text - The text or number to be escaped.
|
|
9
|
+
* @param {boolean} [keepPath=false] - Whether to preserve the path structure (encode each path segment separately).
|
|
10
|
+
* @returns {string|null} The escaped string or null if the input is neither a string nor a number.
|
|
11
|
+
*/
|
|
12
|
+
export default function databaseEscape(text, keepPath = false) {
|
|
13
|
+
// Check if the input is a string or number
|
|
14
|
+
if (typeof text === 'string' || typeof text === 'number') {
|
|
15
|
+
// Convert the value to a string if it's a number
|
|
16
|
+
let new_value = text;
|
|
17
|
+
if (typeof new_value === 'number')
|
|
18
|
+
new_value = String(new_value);
|
|
19
|
+
// Normal escape (do not preserve path)
|
|
20
|
+
if (!keepPath)
|
|
21
|
+
new_value = firebaseEscape.encode(new_value);
|
|
22
|
+
// Escape path segments individually (preserve path structure)
|
|
23
|
+
else {
|
|
24
|
+
// Split path into segments
|
|
25
|
+
new_value = new_value.split('/');
|
|
26
|
+
for (const item in new_value)
|
|
27
|
+
new_value[item] = firebaseEscape.encode(new_value[item]);
|
|
28
|
+
// Join the segments back into a single string
|
|
29
|
+
new_value = new_value.join('/');
|
|
30
|
+
}
|
|
31
|
+
// Return the escaped value
|
|
32
|
+
return new_value;
|
|
33
|
+
}
|
|
34
|
+
// Return null if the input is neither a string nor a number
|
|
35
|
+
else
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var objType = require('../get/objType.cjs');
|
|
4
|
+
var moment = require('moment-timezone');
|
|
5
|
+
var getDBData = require('./getDBData.cjs');
|
|
6
|
+
|
|
7
|
+
// DB
|
|
8
|
+
const tinyCache = {};
|
|
9
|
+
let lastUpdate = { number: null, moment: null };
|
|
10
|
+
let cacheLimit = 2000;
|
|
11
|
+
|
|
12
|
+
// Action
|
|
13
|
+
// Error To JSON
|
|
14
|
+
if (!('toJSON' in Error.prototype)) {
|
|
15
|
+
Object.defineProperty(Error.prototype, 'toJSON', {
|
|
16
|
+
value: function () {
|
|
17
|
+
let alt = {};
|
|
18
|
+
|
|
19
|
+
Object.getOwnPropertyNames(this).forEach(function (key) {
|
|
20
|
+
alt[key] = this[key];
|
|
21
|
+
}, this);
|
|
22
|
+
|
|
23
|
+
return alt;
|
|
24
|
+
},
|
|
25
|
+
configurable: true,
|
|
26
|
+
writable: true,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Handles various logging actions (log, error, info, warn) and stores them in the database.
|
|
32
|
+
* Logs data are stored with a timestamp and are counted by type (log, error, info, warn).
|
|
33
|
+
* When the log count exceeds the specified cache limit, the database is cleared and reset.
|
|
34
|
+
*
|
|
35
|
+
* @param {string} where - The location or context where the log is coming from.
|
|
36
|
+
* @param {string} type - The type of log (log, error, info, or warn).
|
|
37
|
+
* @param {Array} args - The arguments to log (can include strings, numbers, objects, arrays, or errors).
|
|
38
|
+
* @returns {Promise<void>} Resolves once the log is stored in the database.
|
|
39
|
+
*/
|
|
40
|
+
const tinyAction = async function (where, type, args) {
|
|
41
|
+
// Try
|
|
42
|
+
try {
|
|
43
|
+
// Production
|
|
44
|
+
if (!isDebug) {
|
|
45
|
+
// Date Now
|
|
46
|
+
const now = moment();
|
|
47
|
+
|
|
48
|
+
// Update Counter
|
|
49
|
+
let count = tinyCache[where].count[type];
|
|
50
|
+
tinyCache[where].count[type]++;
|
|
51
|
+
|
|
52
|
+
// New Date
|
|
53
|
+
if (
|
|
54
|
+
(lastUpdate.moment && lastUpdate.moment.date() !== now.date()) ||
|
|
55
|
+
tinyCache[where].count[type] > cacheLimit
|
|
56
|
+
) {
|
|
57
|
+
await tinyCache[where].db.remove();
|
|
58
|
+
for (const item in tinyCache[where].count) {
|
|
59
|
+
tinyCache[where].count[item] = 0;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Update Time
|
|
64
|
+
lastUpdate.moment = now;
|
|
65
|
+
lastUpdate.number = lastUpdate.moment.valueOf();
|
|
66
|
+
|
|
67
|
+
// Check Args
|
|
68
|
+
const insertArgs = [];
|
|
69
|
+
for (const item in args) {
|
|
70
|
+
// Is Error
|
|
71
|
+
if (args[item] instanceof Error) {
|
|
72
|
+
try {
|
|
73
|
+
args[item] = JSON.parse(JSON.stringify(args[item]));
|
|
74
|
+
} catch (err) {
|
|
75
|
+
console.error(err);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Object Type
|
|
80
|
+
const type = objType(args[item]);
|
|
81
|
+
|
|
82
|
+
// Insert Args
|
|
83
|
+
if (type === 'string' || type === 'number' || type === 'object' || type === 'array')
|
|
84
|
+
insertArgs.push(args[item]);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Add Log
|
|
88
|
+
if (insertArgs.length > 0) {
|
|
89
|
+
await tinyCache[where].db.child(type).child(count).set({
|
|
90
|
+
time: lastUpdate.number,
|
|
91
|
+
args: insertArgs,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Nope
|
|
96
|
+
else {
|
|
97
|
+
tinyCache[where].count[type]--;
|
|
98
|
+
if (tinyCache[where].count[type] < 0) tinyCache[where].count[type] = 0;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
} catch (err) {
|
|
102
|
+
// Error
|
|
103
|
+
console.error(`ERROR IN ${where} (${type})!`);
|
|
104
|
+
console.error(err);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
// Is Debug
|
|
109
|
+
let isDebug = false;
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Updates the last update time with the provided value, if it's newer than the current one.
|
|
113
|
+
*
|
|
114
|
+
* @param {number} value - The timestamp of the update to check against the last update.
|
|
115
|
+
* @returns {void}
|
|
116
|
+
*/
|
|
117
|
+
const checkLastTime = function (value) {
|
|
118
|
+
// Update
|
|
119
|
+
if (!lastUpdate.number || value > lastUpdate.number) {
|
|
120
|
+
lastUpdate.moment = moment(value);
|
|
121
|
+
lastUpdate.number = lastUpdate.moment.valueOf();
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Generates a logger object with methods for different types of logging (log, error, info, warn).
|
|
127
|
+
* Each log type is stored in the database with a timestamp and arguments.
|
|
128
|
+
*
|
|
129
|
+
* @param {string} where - The location or context where the log is coming from.
|
|
130
|
+
* @returns {Object} The logger object with methods for logging (log, error, info, warn).
|
|
131
|
+
*/
|
|
132
|
+
const loggerGenerator = function (where) {
|
|
133
|
+
// Done
|
|
134
|
+
return {
|
|
135
|
+
// Log
|
|
136
|
+
log: async function () {
|
|
137
|
+
console.log.apply(console, arguments);
|
|
138
|
+
tinyAction(where, 'log', arguments);
|
|
139
|
+
},
|
|
140
|
+
|
|
141
|
+
// Error
|
|
142
|
+
error: async function () {
|
|
143
|
+
console.error.apply(console, arguments);
|
|
144
|
+
tinyAction(where, 'error', arguments);
|
|
145
|
+
},
|
|
146
|
+
|
|
147
|
+
// Info
|
|
148
|
+
info: async function () {
|
|
149
|
+
console.info.apply(console, arguments);
|
|
150
|
+
tinyAction(where, 'info', arguments);
|
|
151
|
+
},
|
|
152
|
+
|
|
153
|
+
// Warning
|
|
154
|
+
warn: async function () {
|
|
155
|
+
console.warn.apply(console, arguments);
|
|
156
|
+
tinyAction(where, 'warn', arguments);
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Database logger module that manages logging actions and stores logs in a database.
|
|
163
|
+
* It provides functionality to start the logger with a new database instance,
|
|
164
|
+
* retrieve the logger instance, change the cache limit, and set debug mode.
|
|
165
|
+
*
|
|
166
|
+
* @module databaseLogger
|
|
167
|
+
*/
|
|
168
|
+
const databaseLogger = {
|
|
169
|
+
/**
|
|
170
|
+
* Starts the logger with a new database instance and initializes cache values.
|
|
171
|
+
*
|
|
172
|
+
* @param {Object} newDB - The new database instance to use for storing logs.
|
|
173
|
+
* @param {string} where - The context or location where the logger will be used.
|
|
174
|
+
* @returns {Promise<Object>} The logger instance with methods for logging.
|
|
175
|
+
*/
|
|
176
|
+
start: async function (newDB, where) {
|
|
177
|
+
// Prepare
|
|
178
|
+
tinyCache[where] = { db: newDB, count: { log: 0, error: 0, info: 0, warn: 0 } };
|
|
179
|
+
let loggerCache = null;
|
|
180
|
+
if (!isDebug) {
|
|
181
|
+
loggerCache = await getDBData(tinyCache[where].db);
|
|
182
|
+
if (loggerCache) {
|
|
183
|
+
try {
|
|
184
|
+
if (loggerCache.log) {
|
|
185
|
+
tinyCache[where].count.log = loggerCache.log.length;
|
|
186
|
+
for (const item in loggerCache.log) {
|
|
187
|
+
if (typeof loggerCache.log[item].time === 'number') {
|
|
188
|
+
checkLastTime(loggerCache.log[item].time);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
if (loggerCache.error) {
|
|
193
|
+
tinyCache[where].count.error = loggerCache.error.length;
|
|
194
|
+
for (const item in loggerCache.error) {
|
|
195
|
+
if (typeof loggerCache.error[item].time === 'number') {
|
|
196
|
+
checkLastTime(loggerCache.error[item].time);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
if (loggerCache.info) {
|
|
201
|
+
tinyCache[where].count.info = loggerCache.info.length;
|
|
202
|
+
for (const item in loggerCache.info) {
|
|
203
|
+
if (typeof loggerCache.info[item].time === 'number') {
|
|
204
|
+
checkLastTime(loggerCache.info[item].time);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
if (loggerCache.warn) {
|
|
209
|
+
tinyCache[where].count.warn = loggerCache.warn.length;
|
|
210
|
+
for (const item in loggerCache.warn) {
|
|
211
|
+
if (typeof loggerCache.warn[item].time === 'number') {
|
|
212
|
+
checkLastTime(loggerCache.warn[item].time);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
} catch (err) {
|
|
217
|
+
console.error(err);
|
|
218
|
+
isDebug = true;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// Complete
|
|
224
|
+
return loggerGenerator(where);
|
|
225
|
+
},
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Retrieves the logger instance for a given context.
|
|
229
|
+
*
|
|
230
|
+
* @param {string} where - The context or location where the logger will be used.
|
|
231
|
+
* @returns {Object} The logger instance with methods for logging.
|
|
232
|
+
*/
|
|
233
|
+
get: function (where) {
|
|
234
|
+
return loggerGenerator(where);
|
|
235
|
+
},
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Changes the cache limit for the logger.
|
|
239
|
+
*
|
|
240
|
+
* @param {number} value - The new cache limit to set.
|
|
241
|
+
* @returns {void}
|
|
242
|
+
*/
|
|
243
|
+
changeCacheLimit: function (value) {
|
|
244
|
+
if (typeof value === 'number') cacheLimit = value;
|
|
245
|
+
},
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Enables or disables debug mode.
|
|
249
|
+
*
|
|
250
|
+
* @param {boolean} value - `true` to enable debug mode, `false` to disable it.
|
|
251
|
+
* @returns {void}
|
|
252
|
+
*/
|
|
253
|
+
setDebugMode: function (value) {
|
|
254
|
+
isDebug = value;
|
|
255
|
+
},
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
module.exports = databaseLogger;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export default databaseLogger;
|
|
2
|
+
declare namespace databaseLogger {
|
|
3
|
+
function start(newDB: Object, where: string): Promise<Object>;
|
|
4
|
+
function get(where: string): Object;
|
|
5
|
+
function changeCacheLimit(value: number): void;
|
|
6
|
+
function setDebugMode(value: boolean): void;
|
|
7
|
+
}
|