fca-smart-shankar 13.0.0 → 16.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.
Files changed (169) hide show
  1. package/.cache/replit/env/latest +56 -0
  2. package/.cache/replit/env/latest.json +1 -0
  3. package/.cache/replit/modules/nodejs-14.res +1 -0
  4. package/.cache/replit/modules/replit.res +1 -0
  5. package/.cache/replit/modules/web.res +1 -0
  6. package/.cache/replit/modules.stamp +0 -0
  7. package/.cache/typescript/5.5/package.json +1 -0
  8. package/.config/configstore/update-notifier-npm.json +4 -0
  9. package/.gitattributes +2 -0
  10. package/.replit +3 -12
  11. package/.upm/store.json +1 -1
  12. package/Extra/Balancer.js +49 -0
  13. package/Extra/Bypass/956/index.js +234 -0
  14. package/Extra/Bypass/test/aaaa.json +170 -0
  15. package/Extra/Bypass/test/index.js +188 -0
  16. package/Extra/Database/index.js +469 -0
  17. package/Extra/ExtraAddons.js +82 -0
  18. package/Extra/ExtraFindUID.js +62 -0
  19. package/Extra/ExtraGetThread.js +365 -0
  20. package/Extra/ExtraScreenShot.js +430 -0
  21. package/Extra/ExtraUptimeRobot.js +38 -0
  22. package/Extra/Html/Classic/script.js +119 -0
  23. package/Extra/Html/Classic/style.css +8 -0
  24. package/Extra/Security/AES_256_GCM/index.js +0 -0
  25. package/Extra/Security/Base/Step_1.js +6 -0
  26. package/Extra/Security/Base/Step_2.js +22 -0
  27. package/Extra/Security/Base/Step_3.js +22 -0
  28. package/Extra/Security/Base/index.js +191 -0
  29. package/Extra/Security/Index.js +5 -0
  30. package/Extra/Security/Step_1.js +6 -0
  31. package/Extra/Security/Step_2.js +22 -0
  32. package/Extra/Security/Step_3.js +22 -0
  33. package/Extra/Src/Change_Environment.js +24 -0
  34. package/Extra/Src/Check_Update.js +67 -0
  35. package/Extra/Src/History.js +115 -0
  36. package/Extra/Src/Instant_Update.js +65 -0
  37. package/Extra/Src/Last-Run.js +65 -0
  38. package/Extra/Src/Premium.js +81 -0
  39. package/Extra/Src/Release_Memory.js +160 -0
  40. package/Extra/Src/Websocket.js +213 -0
  41. package/Extra/Src/image/checkmate.jpg +0 -0
  42. package/Extra/Src/test.js +28 -0
  43. package/Extra/Src/uuid.js +137 -0
  44. package/Func/AcceptAgreement.js +31 -0
  45. package/Func/ClearCache.js +64 -0
  46. package/Func/ReportV1.js +54 -0
  47. package/LICENSE +678 -0
  48. package/Language/index.json +228 -0
  49. package/Main.js +1444 -0
  50. package/README.md +30 -175
  51. package/SECURITY.md +18 -0
  52. package/broadcast.js +44 -0
  53. package/index.js +414 -511
  54. package/logger.js +66 -0
  55. package/package.json +85 -370
  56. package/src/Dev_Horizon_Data.js +125 -0
  57. package/src/Dev_getThreadInfoOLD.js +422 -0
  58. package/src/Dev_shareTest2.js +68 -0
  59. package/src/Dev_shareTest3.js +71 -0
  60. package/src/Premium.js +25 -0
  61. package/src/Screenshot.js +83 -0
  62. package/src/addExternalModule.js +5 -14
  63. package/src/addUserToGroup.js +20 -56
  64. package/src/changeAdminStatus.js +20 -44
  65. package/src/changeArchivedStatus.js +11 -25
  66. package/src/{changeAvatarV2.js → changeAvt.js} +2 -3
  67. package/src/changeBio.js +15 -26
  68. package/src/changeBlockedStatus.js +8 -21
  69. package/src/changeGroupImage.js +24 -53
  70. package/src/changeNickname.js +13 -27
  71. package/src/changeThreadColor.js +19 -22
  72. package/src/changeThreadEmoji.js +11 -24
  73. package/src/createNewGroup.js +20 -38
  74. package/src/createPoll.js +16 -27
  75. package/src/deleteMessage.js +13 -24
  76. package/src/deleteThread.js +12 -25
  77. package/src/editMessage.js +53 -71
  78. package/src/forwardAttachment.js +15 -27
  79. package/src/getAccessToken.js +28 -0
  80. package/src/getCurrentUserID.js +1 -1
  81. package/src/getEmojiUrl.js +8 -10
  82. package/src/getFriendsList.js +15 -25
  83. package/src/getMessage.js +81 -813
  84. package/src/getThreadHistory.js +98 -241
  85. package/src/getThreadInfo.js +287 -90
  86. package/src/getThreadInfoOLD.js +422 -0
  87. package/src/getThreadList.js +157 -214
  88. package/src/getThreadMain.js +220 -0
  89. package/src/getThreadPictures.js +19 -39
  90. package/src/getUID.js +50 -113
  91. package/src/getUserID.js +14 -18
  92. package/src/getUserInfo.js +71 -65
  93. package/src/getUserInfoMain.js +65 -0
  94. package/src/getUserInfoV2.js +32 -0
  95. package/src/getUserInfoV3.js +63 -0
  96. package/src/getUserInfoV4.js +55 -0
  97. package/src/getUserInfoV5.js +61 -0
  98. package/src/handleFriendRequest.js +13 -24
  99. package/src/handleMessageRequest.js +20 -36
  100. package/src/httpGet.js +18 -34
  101. package/src/httpPost.js +18 -35
  102. package/src/httpPostFormData.js +24 -53
  103. package/src/listenMqtt.js +944 -680
  104. package/src/listenMqttV1.js +846 -0
  105. package/src/logout.js +15 -22
  106. package/src/markAsDelivered.js +15 -25
  107. package/src/markAsRead.js +27 -45
  108. package/src/markAsReadAll.js +14 -21
  109. package/src/markAsSeen.js +18 -28
  110. package/src/muteThread.js +12 -17
  111. package/src/removeUserFromGroup.js +17 -47
  112. package/src/resolvePhotoUrl.js +13 -21
  113. package/src/searchForThread.js +13 -23
  114. package/src/sendMessage.js +117 -178
  115. package/src/sendMqttMessage.js +71 -0
  116. package/src/sendTypingIndicator.js +16 -46
  117. package/src/setMessageReaction.js +20 -33
  118. package/src/setPostReaction.js +95 -105
  119. package/src/setTitle.js +18 -34
  120. package/src/shareContact.js +37 -92
  121. package/src/shareLink.js +4 -5
  122. package/src/threadColors.js +18 -110
  123. package/src/unfriend.js +9 -18
  124. package/src/unsendMessage.js +34 -31
  125. package/src/unsendMqttMessage.js +66 -0
  126. package/test/Database_Test.js +4 -0
  127. package/test/Db2.js +530 -0
  128. package/test/Shankar_Database/A_README.md +1 -0
  129. package/test/Shankar_Database/Database.db +0 -0
  130. package/test/data/shareAttach.js +1 -1
  131. package/test/env/.env +0 -0
  132. package/test/example-db.db +0 -0
  133. package/test/memoryleak.js +18 -0
  134. package/test/test.js +1 -1
  135. package/test/testname.js +1342 -0
  136. package/test/testv2.js +3 -0
  137. package/utils.js +2918 -1393
  138. package/CHANGELOG.md +0 -2
  139. package/LICENSE-MIT +0 -21
  140. package/generated-icon.png +0 -0
  141. package/replit.nix +0 -5
  142. package/shankar-fca.json +0 -4
  143. package/src/changeAvatar.js +0 -136
  144. package/src/changeBlockedStatusMqtt.js +0 -80
  145. package/src/changeCover.js +0 -73
  146. package/src/changeName.js +0 -79
  147. package/src/changeUsername.js +0 -59
  148. package/src/createCommentPost.js +0 -230
  149. package/src/createPost.js +0 -277
  150. package/src/data/getThreadInfo.json +0 -1
  151. package/src/editMessageOld.js +0 -67
  152. package/src/follow.js +0 -74
  153. package/src/getAccess.js +0 -112
  154. package/src/getAvatarUser.js +0 -78
  155. package/src/getRegion.js +0 -7
  156. package/src/getThreadHistoryDeprecated.js +0 -93
  157. package/src/getThreadInfoDeprecated.js +0 -80
  158. package/src/getThreadListDeprecated.js +0 -75
  159. package/src/listenNotification.js +0 -85
  160. package/src/pinMessage.js +0 -59
  161. package/src/refreshFb_dtsg.js +0 -89
  162. package/src/searchStickers.js +0 -53
  163. package/src/sendMessageMqtt.js +0 -322
  164. package/src/sendTypingIndicatorV2.js +0 -28
  165. package/src/setMessageReactionMqtt.js +0 -62
  166. package/src/setProfileGuard.js +0 -45
  167. package/src/setStoryReaction.js +0 -64
  168. package/src/stopListenMqtt.js +0 -26
  169. package/src/uploadAttachment.js +0 -94
package/test/Db2.js ADDED
@@ -0,0 +1,530 @@
1
+ /* eslint-disable no-self-assign */
2
+ /* eslint-disable linebreak-style */
3
+ const get = require('lodash/get');
4
+ const set = require('lodash/set');
5
+ const sqlite3 = require('sqlite3');
6
+ const fs = require('fs-extra');
7
+ const request = require('request');
8
+ const deasync = require('deasync');
9
+
10
+ if (!fs.existsSync(process.cwd() + '/Shankar_Database')) {
11
+ fs.mkdirSync(process.cwd() + '/Shankar_Database');
12
+ fs.writeFileSync(process.cwd() + '/Shankar_Database/A_README.md', 'This folder is used by ChernobyL(NANI =)) ) to store data. Do not delete this folder or any of the files in it.', 'utf8');
13
+ }
14
+ var Database = new sqlite3.Database(process.cwd() + "/Shankar_Database/SyntheticDatabase.sqlite");
15
+
16
+ Database.serialize(function() {
17
+ Database.run("CREATE TABLE IF NOT EXISTS json (ID TEXT, json TEXT)");
18
+ });
19
+
20
+ function Lset(key, value) {
21
+ try {
22
+ //check if key is exists if yes then update it
23
+ if (Lhas(key)) {
24
+ var done = false;
25
+ Database.run(`UPDATE json SET json = (?) WHERE ID = (?)`, [JSON.stringify(value), key], function(err) {
26
+ done = true;
27
+ });
28
+ deasync.loopWhile(function(){
29
+ return !done;
30
+ });
31
+ return;
32
+ }
33
+ else {
34
+ var done = false;
35
+ Database.run(`INSERT INTO json(ID, json) VALUES(?, ?)`, [key, JSON.stringify(value)], function(err) {
36
+ done = true;
37
+ });
38
+ deasync.loopWhile(function(){
39
+ return !done;
40
+ });
41
+ return;
42
+ }
43
+ }
44
+ catch (e) {
45
+ console.log(e);
46
+ return false;
47
+ }
48
+ }
49
+
50
+ function Lget(key) {
51
+ try {
52
+ var done = false;
53
+ var Data = undefined;
54
+ Database.get(`SELECT * FROM json WHERE ID = (?)`, [key], function(err, row) {
55
+ Data = row;
56
+ done = true;
57
+ });
58
+ deasync.loopWhile(function(){
59
+ return !done;
60
+ });
61
+ if (Data === undefined) return undefined;
62
+ return JSON.parse(Data.json);
63
+ }
64
+ catch (e) {
65
+ console.log(e);
66
+ return false;
67
+ }
68
+ }
69
+
70
+ function Lhas(key) {
71
+ try {
72
+ var done = false;
73
+ var Data = undefined;
74
+ Database.get(`SELECT * FROM json WHERE ID = (?)`, [key], function(err, row) {
75
+ Data = row;
76
+ done = true;
77
+ });
78
+ deasync.loopWhile(function(){
79
+ return !done;
80
+ });
81
+ if (Data === undefined) return false;
82
+ return true;
83
+ }
84
+ catch (e) {
85
+ console.log(e);
86
+ return false;
87
+ }
88
+ }
89
+
90
+ function Lremove(key) {
91
+ try {
92
+ var done = false;
93
+ Database.run(`DELETE FROM json WHERE ID = (?)`, [key], function(err) {
94
+ done = true;
95
+ });
96
+ deasync.loopWhile(function(){
97
+ return !done;
98
+ });
99
+ return;
100
+ }
101
+ catch (e) {
102
+ console.log(e);
103
+ return false;
104
+ }
105
+ }
106
+
107
+ function LremoveMultiple(keys) {
108
+ try {
109
+ for (const key of keys) {
110
+ Database.run(`DELETE FROM json WHERE ID = (?)`, [key], function(err) {});
111
+ }
112
+ return true;
113
+ }
114
+ catch (e) {
115
+ console.log(e);
116
+ return false;
117
+ }
118
+ }
119
+
120
+ function Llist() {
121
+ var done = false;
122
+ var Data = undefined;
123
+ Database.all(`SELECT * FROM json`,[], function(err, rows) {
124
+ Data = rows;
125
+ done = true;
126
+ });
127
+ deasync.loopWhile(function(){
128
+ return !done;
129
+ });
130
+ return Data;
131
+ }
132
+
133
+ function Replit_Set(key, value) {
134
+ try {
135
+ var done = false;
136
+
137
+ request({
138
+ url: process.env.REPLIT_DB_URL,
139
+ method: "POST",
140
+ headers: {
141
+ 'Content-Type': 'application/x-www-form-urlencoded',
142
+ },
143
+ body: `${encodeURIComponent(key)}=${encodeURIComponent(JSON.stringify(value))}`
144
+
145
+ }, function (error, response, body) {
146
+ done = true;
147
+ });
148
+
149
+ deasync.loopWhile(function(){
150
+ return !done;
151
+ });
152
+
153
+ return;
154
+
155
+ }
156
+ catch (e) {
157
+ console.log(e);
158
+ return false;
159
+ }
160
+ }
161
+
162
+ function Replit_Get(key) {
163
+ try {
164
+ var done = false;
165
+ var response = null;
166
+
167
+ request(process.env.REPLIT_DB_URL + "/" + key, function (error, res, body) {
168
+ if (!error && res.statusCode == 200) {
169
+ response = body;
170
+ }
171
+ done = true;
172
+ });
173
+
174
+ deasync.loopWhile(function(){
175
+ return !done;
176
+ });
177
+
178
+ return JSON.parse(response);
179
+ }
180
+ catch (e) {
181
+ console.log(e);
182
+ return false;
183
+ }
184
+ }
185
+
186
+ function Replit_Has(key) {
187
+ try {
188
+ var done = false;
189
+ var response = null;
190
+
191
+ request(process.env.REPLIT_DB_URL + "/" + key, function (error, res, body) {
192
+ if (!error && res.statusCode == 200) {
193
+ response = body;
194
+ }
195
+ done = true;
196
+ });
197
+
198
+ deasync.loopWhile(function(){
199
+ return !done;
200
+ });
201
+
202
+ return response != null;
203
+ }
204
+ catch (e) {
205
+ console.log(e);
206
+ return false;
207
+ }
208
+ }
209
+
210
+ function Replit_Remove(key) {
211
+ try {
212
+ var done = false;
213
+ request.delete(process.env.REPLIT_DB_URL + "/" + key , function (error, response, body) {
214
+ done = true;
215
+ });
216
+
217
+ deasync.loopWhile(function(){
218
+ return !done;
219
+ });
220
+
221
+ return;
222
+ }
223
+ catch (e) {
224
+ console.log(e);
225
+ return false;
226
+ }
227
+ }
228
+ function Replit_RemoveMultiple(keys) {
229
+ try {
230
+ for (const key of keys) {
231
+ request.delete(process.env.REPLIT_DB_URL + "/" + key , function (error, response, body) {});
232
+ }
233
+ return true;
234
+ }
235
+ catch (e) {
236
+ console.log(e);
237
+ return false;
238
+ }
239
+ }
240
+
241
+ function Replit_List() {
242
+ var done = false;
243
+ var response = null;
244
+
245
+ request(process.env.REPLIT_DB_URL + "?encode=true" + `&prefix=${encodeURIComponent("")}`, function (error, res, body) {
246
+ if (!error && res.statusCode == 200) {
247
+ response = body;
248
+ }
249
+ done = true;
250
+
251
+ });
252
+
253
+ deasync.loopWhile(function(){
254
+ return !done;
255
+ });
256
+
257
+ if (response.length === 0) {
258
+ return [];
259
+ }
260
+ return response.split("\n").map(decodeURIComponent);
261
+ }
262
+
263
+
264
+ var methods = {
265
+ fetch: function(db, params, options) {
266
+ let fetched = db.prepare(`SELECT * FROM ${options.table} WHERE ID = (?)`).get(params.id);
267
+ if (!fetched) return null;
268
+ try {
269
+ fetched = JSON.parse(fetched.json);
270
+ } catch (e) {
271
+ fetched = fetched.json;
272
+ }
273
+ if (params.ops.target) fetched = get(fetched, params.ops.target);
274
+ return fetched;
275
+ },
276
+ set: function(db, params, options) {
277
+ let fetched = db.prepare(`SELECT * FROM ${options.table} WHERE ID = (?)`).get(params.id);
278
+ if (!fetched) {
279
+ db.prepare(`INSERT INTO ${options.table} (ID,json) VALUES (?,?)`).run(params.id, '{}');
280
+ fetched = db.prepare(`SELECT * FROM ${options.table} WHERE ID = (?)`).get(params.id);
281
+ }
282
+ try {
283
+ fetched = JSON.parse(fetched);
284
+ } catch (e) {
285
+ fetched = fetched;
286
+ }
287
+ if (typeof fetched === 'object' && params.ops.target) {
288
+ params.data = JSON.parse(params.data);
289
+ params.data = set(fetched, params.ops.target, params.data);
290
+ }
291
+ else if (params.ops.target) throw new TypeError('Cannot target a non-object.');
292
+ db.prepare(`UPDATE ${options.table} SET json = (?) WHERE ID = (?)`).run(JSON.stringify(params.data), params.id);
293
+ let newData = db.prepare(`SELECT * FROM ${options.table} WHERE ID = (?)`).get(params.id).json;
294
+ if (newData === '{}') return null;
295
+ else {
296
+ try { newData = JSON.parse(newData);
297
+ }
298
+ catch (e) {
299
+ newData = newData;
300
+ }
301
+ return newData;
302
+ }
303
+ },
304
+ add: function addDB(db, params, options) {
305
+ let fetched = db.prepare(`SELECT * FROM ${options.table} WHERE ID = (?)`).get(params.id);
306
+ if (!fetched) {
307
+ db.prepare(`INSERT INTO ${options.table} (ID,json) VALUES (?,?)`).run(params.id, '{}');
308
+ fetched = db.prepare(`SELECT * FROM ${options.table} WHERE ID = (?)`).get(params.id);
309
+ }
310
+ if (params.ops.target) {
311
+ try {
312
+ fetched = JSON.parse(fetched);
313
+ }
314
+ catch (e) {
315
+ fetched = fetched;
316
+ }
317
+ let oldValue = get(fetched, params.ops.target);
318
+ if (oldValue === undefined) oldValue = 0;
319
+ else if (isNaN(oldValue)) throw new Error(`Data @ ID: "${params.id}" IS NOT A number.\nFOUND: ${fetched}\nEXPECTED: number`);
320
+ params.data = set(fetched, params.ops.target, oldValue + JSON.parse(params.data));
321
+ }
322
+ else {
323
+ if (fetched.json === '{}') fetched.json = 0;
324
+ try {
325
+ fetched.json = JSON.parse(fetched);
326
+ } catch (e) {
327
+ fetched.json = fetched.json;
328
+ }
329
+ if (isNaN(fetched.json)) throw new Error(`Data @ ID: "${params.id}" IS NOT A number.\nFOUND: ${fetched.json}\nEXPECTED: number`);
330
+ params.data = parseInt(fetched.json, 10) + parseInt(params.data, 10);
331
+ }
332
+ db.prepare(`UPDATE ${options.table} SET json = (?) WHERE ID = (?)`).run(JSON.stringify(params.data), params.id);
333
+ let newData = db.prepare(`SELECT * FROM ${options.table} WHERE ID = (?)`).get(params.id).json;
334
+ if (newData === '{}') return null;
335
+ else {
336
+ try {
337
+ newData = JSON.parse(newData);
338
+ }
339
+ catch (e) {
340
+ newData = newData;
341
+ }
342
+ return newData;
343
+ }
344
+ },
345
+ subtract: function subtractDB(db, params, options) {
346
+ let fetched = db.prepare(`SELECT * FROM ${options.table} WHERE ID = (?)`).get(params.id);
347
+ if (!fetched) {
348
+ db.prepare(`INSERT INTO ${options.table} (ID,json) VALUES (?,?)`).run(params.id, '{}');
349
+ fetched = db.prepare(`SELECT * FROM ${options.table} WHERE ID = (?)`).get(params.id);
350
+ }
351
+ if (params.ops.target) {
352
+ try { fetched = JSON.parse(fetched); } catch (e) {}
353
+ params.data = JSON.parse(params.data);
354
+ let oldValue = get(fetched, params.ops.target);
355
+ if (oldValue === undefined) oldValue = 0;
356
+ else if (isNaN(oldValue)) throw new Error('Target is not a number.');
357
+ params.data = set(fetched, params.ops.target, oldValue - params.data);
358
+ } else {
359
+ if (fetched.json === '{}') fetched.json = 0;
360
+ else fetched.json = JSON.parse(fetched.json);
361
+ try { fetched.json = JSON.parse(fetched); } catch (e) {}
362
+ if (isNaN(fetched.json)) throw new Error('Target is not a number.');
363
+ params.data = parseInt(fetched.json, 10) - parseInt(params.data, 10);
364
+ }
365
+ params.data = JSON.stringify(params.data);
366
+ db.prepare(`UPDATE ${options.table} SET json = (?) WHERE ID = (?)`).run(params.data, params.id);
367
+ let newData = db.prepare(`SELECT * FROM ${options.table} WHERE ID = (?)`).get(params.id).json;
368
+ if (newData === '{}') return null;
369
+ else {
370
+ try { newData = JSON.parse(newData); } catch (e) {}
371
+ return newData;
372
+ }
373
+ },
374
+ push: function pushDB(db, params, options) {
375
+ let fetched = db.prepare(`SELECT * FROM ${options.table} WHERE ID = (?)`).get(params.id);
376
+ if (!fetched) {
377
+ db.prepare(`INSERT INTO ${options.table} (ID,json) VALUES (?,?)`).run(params.id, '{}');
378
+ fetched = db.prepare(`SELECT * FROM ${options.table} WHERE ID = (?)`).get(params.id);
379
+ }
380
+ if (params.ops.target) {
381
+ fetched = JSON.parse(fetched.json);
382
+ try { fetched = JSON.parse(fetched); } catch (e) {}
383
+ params.data = JSON.parse(params.data);
384
+ if (typeof fetched !== 'object') throw new TypeError('Cannot push into a non-object.');
385
+ let oldArray = get(fetched, params.ops.target);
386
+ if (oldArray === undefined) oldArray = [];
387
+ else if (!Array.isArray(oldArray)) throw new TypeError('Target is not an array.');
388
+ oldArray.push(params.data);
389
+ params.data = set(fetched, params.ops.target, oldArray);
390
+ } else {
391
+ if (fetched.json === '{}') fetched.json = [];
392
+ else fetched.json = JSON.parse(fetched.json);
393
+ try { fetched.json = JSON.parse(fetched.json); } catch (e) {}
394
+ params.data = JSON.parse(params.data);
395
+ if (!Array.isArray(fetched.json)) throw new TypeError('Target is not an array.');
396
+ fetched.json.push(params.data);
397
+ params.data = fetched.json;
398
+ }
399
+ params.data = JSON.stringify(params.data);
400
+ db.prepare(`UPDATE ${options.table} SET json = (?) WHERE ID = (?)`).run(params.data, params.id);
401
+ let newData = db.prepare(`SELECT * FROM ${options.table} WHERE ID = (?)`).get(params.id).json;
402
+ if (newData === '{}') return null;
403
+ else {
404
+ newData = JSON.parse(newData);
405
+ try { newData = JSON.parse(newData); } catch (e) {}
406
+ return newData;
407
+ }
408
+ },
409
+ delete: function deleteDB(db, params, options) {
410
+ const unset = require('lodash/unset');
411
+ let fetched = db.prepare(`SELECT * FROM ${options.table} WHERE ID = (?)`).get(params.id);
412
+ if (!fetched) return false;
413
+ else fetched = JSON.parse(fetched.json);
414
+ try { fetched = JSON.parse(fetched); } catch (e) {}
415
+ if (typeof fetched === 'object' && params.ops.target) {
416
+ unset(fetched, params.ops.target);
417
+ fetched = JSON.stringify(fetched);
418
+ db.prepare(`UPDATE ${options.table} SET json = (?) WHERE ID = (?)`).run(fetched, params.id);
419
+ return true;
420
+ }
421
+ else if (params.ops.target) throw new TypeError('Target is not an object.');
422
+ else db.prepare(`DELETE FROM ${options.table} WHERE ID = (?)`).run(params.id);
423
+ return true;
424
+ },
425
+ has: function hasDB(db, params, options) {
426
+ let fetched = db.prepare(`SELECT * FROM ${options.table} WHERE ID = (?)`).get(params.id);
427
+ if (!fetched) return false;
428
+ else fetched = JSON.parse(fetched.json);
429
+ try { fetched = JSON.parse(fetched); } catch (e) {}
430
+ if (params.ops.target) fetched = get(fetched, params.ops.target);
431
+ return (typeof fetched != 'undefined');
432
+ },
433
+ all: function allDB(db, params, options) {
434
+ var stmt = db.prepare(`SELECT * FROM ${options.table} WHERE ID IS NOT NULL`);
435
+ let resp = [];
436
+ for (var row of stmt.iterate()) {
437
+ try {
438
+ resp.push({
439
+ ID: row.ID,
440
+ data: JSON.parse(row.json)
441
+ });
442
+ }
443
+ catch (e) {
444
+ return [];
445
+ }
446
+ }
447
+ return resp;
448
+ },
449
+ type: function typeDB(db, params, options) {
450
+ let fetched = db.prepare(`SELECT * FROM ${options.table} WHERE ID = (?)`).get(params.id);
451
+ if (!fetched) return null; // If empty, return null
452
+ fetched = JSON.parse(fetched.json);
453
+ try { fetched = JSON.parse(fetched); } catch (e) {}
454
+ if (params.ops.target) fetched = get(fetched, params.ops.target); // Get prop using dot notation
455
+ return typeof fetched;
456
+ },
457
+ clear: function clearDB(db, params, options) {
458
+ let fetched = db.prepare(`DELETE FROM ${options.table}`).run();
459
+ if(!fetched) return null;
460
+ return fetched.changes;
461
+
462
+ }
463
+ };
464
+
465
+
466
+ function arbitrate(method, params) {
467
+ let options = {table: "json"};
468
+ db.prepare(`CREATE TABLE IF NOT EXISTS ${options.table} (ID TEXT, json TEXT)`).run();
469
+ if (params.ops.target && params.ops.target[0] === ".") params.ops.target = params.ops.target.slice(1); // Remove prefix if necessary
470
+ if (params.data && params.data === Infinity) throw new TypeError(`You cannot set Infinity into the database @ ID: ${params.id}`);
471
+ if (params.id && typeof params.id == "string" && params.id.includes(".")) {
472
+ let unparsed = params.id.split(".");
473
+ params.id = unparsed.shift();
474
+ params.ops.target = unparsed.join(".");
475
+ }
476
+ return methods[method](db, params, options);
477
+ }
478
+
479
+
480
+ module.exports = function ChernobyL(Local) {
481
+ if (Local && process.env["REPL_ID"]) {
482
+ return {
483
+ set: Lset,
484
+ get: Lget,
485
+ has: Lhas,
486
+ delete: Lremove,
487
+ deleteMultiple: LremoveMultiple,
488
+ list: Llist
489
+ };
490
+ } else if (!Local && process.env["REPL_ID"]) {
491
+ return {
492
+ set: Replit_Set,
493
+ get: Replit_Get,
494
+ has: Replit_Has,
495
+ delete: Replit_Remove,
496
+ deleteMultiple: Replit_RemoveMultiple,
497
+ list: Replit_List
498
+ };
499
+ }
500
+ else if (Local && !process.env["REPL_ID"]) {
501
+ return {
502
+ set: Lset,
503
+ get: Lget,
504
+ has: Lhas,
505
+ delete: Lremove,
506
+ deleteMultiple: LremoveMultiple,
507
+ list: Llist
508
+ };
509
+ }
510
+ else if (!Local && !process.env["REPL_ID"]) {
511
+ return {
512
+ set: Lset,
513
+ get: Lget,
514
+ has: Lhas,
515
+ delete: Lremove,
516
+ deleteMultiple: LremoveMultiple,
517
+ list: Llist
518
+ };
519
+ }
520
+ else {
521
+ return {
522
+ set: Lset,
523
+ get: Lget,
524
+ has: Lhas,
525
+ delete: Lremove,
526
+ deleteMultiple: LremoveMultiple,
527
+ list: Llist
528
+ };
529
+ }
530
+ };
@@ -0,0 +1 @@
1
+ This folder is used by ChernobyL(NANI =)) ) to store data. Do not delete this folder or any of the files in it.
@@ -143,4 +143,4 @@ module.exports = {
143
143
  "timestamp": "1487078180265"
144
144
  }
145
145
  }
146
- }
146
+ };
package/test/env/.env ADDED
File without changes
File without changes
@@ -0,0 +1,18 @@
1
+ const memwatch = require('memwatch-next');
2
+
3
+ // bắt đầu theo dõi memory
4
+ memwatch.on('leak', function(info) {
5
+ console.error('memory leak detected:');
6
+ console.error(info);
7
+ });
8
+
9
+ // Tạo một object để tạo memory leak
10
+ let myObj = {};
11
+ setInterval(function() {
12
+ for (let i = 0; i < 10000; i++) {
13
+ myObj[i] = new Array(10000);
14
+ }
15
+ }, 1000);
16
+
17
+ // force garbage collection để release memory leak
18
+ memwatch.gc();
package/test/test.js CHANGED
@@ -358,7 +358,7 @@ describe('Login:', function() {
358
358
  assert(getType(v.type) === "String");
359
359
  assert(v.hasOwnProperty("profileUrl")); // This can be null if the account is disabled
360
360
  assert(getType(v.isBirthday) === "Boolean");
361
- })
361
+ });
362
362
  done();
363
363
  } catch(e){
364
364
  done(e);