alicezetion 1.7.1 → 1.7.3
Sign up to get free protection for your applications and to get access to all the features.
- package/.cache/replit/__replit_disk_meta.json +1 -1
- package/.cache/replit/nix/env.json +1 -1
- package/Extra/Database/index.js +399 -0
- package/Extra/Database/methods.js +286 -0
- package/Extra/ExtraAddons.js +213 -0
- package/Extra/ExtraGetThread.js +1 -0
- package/Extra/ExtraUptimeRobot.js +59 -0
- package/Extra/PM2/ecosystem.config.js +23 -0
- package/Extra/Src/Last-Run.js +48 -0
- package/Language/index.json +151 -0
- package/StateCrypt.js +22 -0
- package/broadcast.js +42 -0
- package/index.js +655 -120
- package/logger.js +21 -0
- package/package.json +37 -25
- package/replit.nix +3 -4
- package/src/addExternalModule.js +13 -5
- package/src/addUserToGroup.js +36 -12
- package/src/changeAdminStatus.js +85 -37
- package/src/changeArchivedStatus.js +15 -9
- package/src/changeAvt.js +91 -0
- package/src/changeBio.js +13 -8
- package/src/changeBlockedStatus.js +14 -8
- package/src/changeGroupImage.js +28 -13
- package/src/changeNickname.js +22 -11
- package/src/changeThreadColor.js +16 -10
- package/src/changeThreadEmoji.js +18 -9
- package/src/chat.js +401 -280
- package/src/createNewGroup.js +18 -10
- package/src/createPoll.js +17 -11
- package/src/deleteMessage.js +17 -10
- package/src/deleteThread.js +17 -10
- package/src/forwardAttachment.js +15 -9
- package/src/getAccessToken.js +32 -0
- package/src/getCurrentUserID.js +1 -1
- package/src/getEmojiUrl.js +3 -2
- package/src/getFriendsList.js +18 -10
- package/src/getMessage.js +84 -0
- package/src/getThreadHistory.js +156 -59
- package/src/getThreadHistoryDeprecated.js +26 -15
- package/src/getThreadInfo.js +68 -42
- package/src/getThreadInfoDeprecated.js +25 -13
- package/src/getThreadList.js +112 -53
- package/src/getThreadListDeprecated.js +30 -12
- package/src/getThreadPictures.js +25 -13
- package/src/getUserID.js +9 -7
- package/src/getUserInfo.js +12 -10
- package/src/getUserInfoV2.js +35 -0
- package/src/handleFriendRequest.js +36 -35
- package/src/handleMessageRequest.js +18 -10
- package/src/httpGet.js +20 -13
- package/src/httpPost.js +19 -13
- package/src/httpPostFormData.js +46 -0
- package/src/listenMqtt.js +1224 -621
- package/src/logout.js +18 -13
- package/src/markAsDelivered.js +17 -10
- package/src/markAsRead.js +36 -24
- package/src/markAsSeen.js +22 -12
- package/src/muteThread.js +15 -9
- package/src/{setMessageReaction.js → react.js} +20 -9
- package/src/removeUserFromGroup.js +38 -11
- package/src/resolvePhotoUrl.js +9 -6
- package/src/searchForThread.js +14 -8
- package/src/{markAsReadAll.js → seen.js} +17 -10
- package/src/sendTypingIndicator.js +44 -19
- package/src/setPostReaction.js +63 -22
- package/src/setTitle.js +22 -12
- package/src/threadColors.js +17 -19
- package/src/unfriend.js +15 -9
- package/src/{unsendMessage.js → unsend.js} +9 -8
- package/utils.js +120 -27
- package/.travis.yml +0 -6
- package/src/forwardMessage.js +0 -0
- package/src/listen.js +0 -553
- package/src/listenMqtt-Test.js +0 -687
- package/src/sendMessage.js +0 -315
- package/test/data/shareAttach.js +0 -146
- package/test/data/something.mov +0 -0
- package/test/data/test.png +0 -0
- package/test/data/test.txt +0 -7
- package/test/example-config.json +0 -18
- package/test/test-page.js +0 -140
- package/test/test.js +0 -385
@@ -1 +1 @@
|
|
1
|
-
{"nonce":
|
1
|
+
{"nonce":6115256902394364261,"last_updated":{"seconds":1696065418,"nanos":659727000}}
|
@@ -1 +1 @@
|
|
1
|
-
{"entries":{"replit.nix":{"env":{"AR":"ar","AS":"as","CC":"gcc","CONFIG_SHELL":"/nix/store/dpjnjrqbgbm8a5wvi1hya01vd8wyvsq4-bash-4.4-p23/bin/bash","CXX":"g++","HOST_PATH":"/nix/store/bwxril521b35zlf4x2g32hll64rzfhck-nodejs-16.7.0/bin:/nix/store/
|
1
|
+
{"entries":{"replit.nix":{"env":{"AR":"ar","AS":"as","CC":"gcc","CONFIG_SHELL":"/nix/store/dpjnjrqbgbm8a5wvi1hya01vd8wyvsq4-bash-4.4-p23/bin/bash","CXX":"g++","HOST_PATH":"/nix/store/bwxril521b35zlf4x2g32hll64rzfhck-nodejs-16.7.0/bin:/nix/store/1570w56jrkvr90w9x158vyb5vahnk18v-coreutils-8.32/bin:/nix/store/ihxk2vlm0vi7c4j3gpm084kbxvz6v585-findutils-4.8.0/bin:/nix/store/kjx1mv85c5cgsrr4bwar22j7hbwj834m-diffutils-3.7/bin:/nix/store/gm2w08wwsa3vd500d8vq879s2lv65ldh-gnused-4.8/bin:/nix/store/v0slhpb2y3xa7gmv4q6gblkdk7n0f09j-gnugrep-3.6/bin:/nix/store/2wn093wbc6ps4brcsppxjd14vxvaa8a2-gawk-5.1.0/bin:/nix/store/5bxrjkyvqmzn1p897652y3lwa9fxagpw-gnutar-1.34/bin:/nix/store/liva1jnjdskrn57s42kfawr2zz66szzm-gzip-1.10/bin:/nix/store/ih2zkh2mbrx2c766ryk2i9hhlkly7snr-bzip2-1.0.6.0.2-bin/bin:/nix/store/pvkiiw0mp1yx0b21b7k105yywccychgh-gnumake-4.3/bin:/nix/store/dpjnjrqbgbm8a5wvi1hya01vd8wyvsq4-bash-4.4-p23/bin:/nix/store/aicl3kwfnaizk45aygm8bviqv7lk0a16-patch-2.7.6/bin:/nix/store/7jk6k46f56rszzc1bxi8mdrvcw53pym4-xz-5.2.5-bin/bin","LD":"ld","LOCALE_ARCHIVE":"/usr/lib/locale/locale-archive","NIX_BINTOOLS":"/nix/store/29bjq5hw1qglybp1a5f3ij9gxc2fyf94-binutils-wrapper-2.35.1","NIX_BINTOOLS_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu":"1","NIX_BUILD_CORES":"4","NIX_BUILD_TOP":"/tmp","NIX_CC":"/nix/store/4xs1xyj8728yvh9y5v6ji819kwgfy2fv-gcc-wrapper-10.3.0","NIX_CC_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu":"1","NIX_CFLAGS_COMPILE":" -frandom-seed=wn4q3px71j -isystem /nix/store/bwxril521b35zlf4x2g32hll64rzfhck-nodejs-16.7.0/include -isystem /nix/store/bwxril521b35zlf4x2g32hll64rzfhck-nodejs-16.7.0/include","NIX_ENFORCE_NO_NATIVE":"1","NIX_HARDENING_ENABLE":"fortify stackprotector pic strictoverflow format relro bindnow","NIX_INDENT_MAKE":"1","NIX_LDFLAGS":"-rpath /nix/store/wn4q3px71j98mf9lcy14i6xlgmfhk75m-nix-shell/lib64 -rpath /nix/store/wn4q3px71j98mf9lcy14i6xlgmfhk75m-nix-shell/lib ","NIX_STORE":"/nix/store","NM":"nm","NODE_PATH":"/nix/store/bwxril521b35zlf4x2g32hll64rzfhck-nodejs-16.7.0/lib/node_modules","OBJCOPY":"objcopy","OBJDUMP":"objdump","PATH":"/nix/store/w07a7k61dw5gnsyxj3kgcq3shr76jax8-bash-interactive-4.4-p23/bin:/nix/store/435paza0j48aa9vgvf6r2l12nrg4ld11-patchelf-0.12/bin:/nix/store/4xs1xyj8728yvh9y5v6ji819kwgfy2fv-gcc-wrapper-10.3.0/bin:/nix/store/dlni53myj53kx20pi4yhm7p68lw17b07-gcc-10.3.0/bin:/nix/store/6z35qvn00xrjvaznv9kfy8xddbbdz4gl-glibc-2.33-47-bin/bin:/nix/store/1570w56jrkvr90w9x158vyb5vahnk18v-coreutils-8.32/bin:/nix/store/29bjq5hw1qglybp1a5f3ij9gxc2fyf94-binutils-wrapper-2.35.1/bin:/nix/store/v8imx1nvyz0hgvx9cbcmh6gp4ngw3ffj-binutils-2.35.1/bin:/nix/store/bwxril521b35zlf4x2g32hll64rzfhck-nodejs-16.7.0/bin:/nix/store/1570w56jrkvr90w9x158vyb5vahnk18v-coreutils-8.32/bin:/nix/store/ihxk2vlm0vi7c4j3gpm084kbxvz6v585-findutils-4.8.0/bin:/nix/store/kjx1mv85c5cgsrr4bwar22j7hbwj834m-diffutils-3.7/bin:/nix/store/gm2w08wwsa3vd500d8vq879s2lv65ldh-gnused-4.8/bin:/nix/store/v0slhpb2y3xa7gmv4q6gblkdk7n0f09j-gnugrep-3.6/bin:/nix/store/2wn093wbc6ps4brcsppxjd14vxvaa8a2-gawk-5.1.0/bin:/nix/store/5bxrjkyvqmzn1p897652y3lwa9fxagpw-gnutar-1.34/bin:/nix/store/liva1jnjdskrn57s42kfawr2zz66szzm-gzip-1.10/bin:/nix/store/ih2zkh2mbrx2c766ryk2i9hhlkly7snr-bzip2-1.0.6.0.2-bin/bin:/nix/store/pvkiiw0mp1yx0b21b7k105yywccychgh-gnumake-4.3/bin:/nix/store/dpjnjrqbgbm8a5wvi1hya01vd8wyvsq4-bash-4.4-p23/bin:/nix/store/aicl3kwfnaizk45aygm8bviqv7lk0a16-patch-2.7.6/bin:/nix/store/7jk6k46f56rszzc1bxi8mdrvcw53pym4-xz-5.2.5-bin/bin","RANLIB":"ranlib","READELF":"readelf","SIZE":"size","SOURCE_DATE_EPOCH":"315532800","STRINGS":"strings","STRIP":"strip","XDG_DATA_DIRS":"/nix/store/435paza0j48aa9vgvf6r2l12nrg4ld11-patchelf-0.12/share","_":"/nix/store/1570w56jrkvr90w9x158vyb5vahnk18v-coreutils-8.32/bin/env","__ETC_PROFILE_SOURCED":"1","buildInputs":"/nix/store/bwxril521b35zlf4x2g32hll64rzfhck-nodejs-16.7.0","builder":"/nix/store/dpjnjrqbgbm8a5wvi1hya01vd8wyvsq4-bash-4.4-p23/bin/bash","configureFlags":"","depsBuildBuild":"","depsBuildBuildPropagated":"","depsBuildTarget":"","depsBuildTargetPropagated":"","depsHostHost":"","depsHostHostPropagated":"","depsTargetTarget":"","depsTargetTargetPropagated":"","doCheck":"","doInstallCheck":"","name":"nix-shell","nativeBuildInputs":"","nobuildPhase":"echo\necho \"This derivation is not meant to be built, aborting\";\necho\nexit 1\n","out":"/nix/store/wn4q3px71j98mf9lcy14i6xlgmfhk75m-nix-shell","outputs":"out","patches":"","phases":"nobuildPhase","propagatedBuildInputs":"","propagatedNativeBuildInputs":"","shell":"/nix/store/dpjnjrqbgbm8a5wvi1hya01vd8wyvsq4-bash-4.4-p23/bin/bash","shellHook":"","stdenv":"/nix/store/r4bl79l2bdjawmr2rhhqvci56qh0fkvv-stdenv-linux","strictDeps":"","system":"x86_64-linux"},"dependencies":[{"path":"replit.nix","mod_time":"2023-09-30T02:46:03.650607133Z"}],"channel":"","channel_nix_path":"","production":null}}}
|
@@ -0,0 +1,399 @@
|
|
1
|
+
/* eslint-disable linebreak-style */
|
2
|
+
/* eslint-disable no-global-assign */
|
3
|
+
|
4
|
+
/**
|
5
|
+
*
|
6
|
+
*/
|
7
|
+
|
8
|
+
// Require Database
|
9
|
+
var Database = require("better-sqlite3");
|
10
|
+
const { join } = require("path");
|
11
|
+
var db;
|
12
|
+
// Create Database Under Conditions
|
13
|
+
if (!db) db = new Database(join(__dirname, "../Databasethread.sqlite"));
|
14
|
+
|
15
|
+
|
16
|
+
var { fetch,set,add,subtract,push,deleteDB,has,all,type,clear } = require("./methods");
|
17
|
+
|
18
|
+
// Declare Methods
|
19
|
+
var methods = {
|
20
|
+
fetch: fetch,
|
21
|
+
set: set,
|
22
|
+
add: add,
|
23
|
+
subtract: subtract,
|
24
|
+
push: push,
|
25
|
+
delete: deleteDB,
|
26
|
+
has: has,
|
27
|
+
all: all,
|
28
|
+
type: type,
|
29
|
+
clear: clear
|
30
|
+
};
|
31
|
+
|
32
|
+
module.exports = {
|
33
|
+
/**
|
34
|
+
* Package version. Community requested feature.
|
35
|
+
* console.log(require('quick.db').version);
|
36
|
+
*/
|
37
|
+
version: "1.1.1",
|
38
|
+
|
39
|
+
/**
|
40
|
+
* This function fetches data from a key in the database. (alias: .get())
|
41
|
+
* @param {key} input any string as a key. Also allows for dot notation following the key.
|
42
|
+
* @param {options} [input={ target: null }] Any options to be added to the request.
|
43
|
+
* @returns {data} the data requested.
|
44
|
+
*/
|
45
|
+
|
46
|
+
fetch: function (key, ops) {
|
47
|
+
if (!key)
|
48
|
+
throw new TypeError(
|
49
|
+
"No key specified."
|
50
|
+
);
|
51
|
+
return arbitrate("fetch", { id: key, ops: ops || {} });
|
52
|
+
},
|
53
|
+
get: function (key, ops) {
|
54
|
+
if (!key)
|
55
|
+
throw new TypeError(
|
56
|
+
"No key specified."
|
57
|
+
);
|
58
|
+
return arbitrate("fetch", { id: key, ops: ops || {} });
|
59
|
+
},
|
60
|
+
|
61
|
+
/**
|
62
|
+
* This function sets new data based on a key in the database.
|
63
|
+
* @param {key} input any string as a key. Also allows for dot notation following the key.
|
64
|
+
* @param {options} [input={ target: null }] Any options to be added to the request.
|
65
|
+
* @returns {data} the updated data.
|
66
|
+
*/
|
67
|
+
|
68
|
+
set: function (key, value, ops) {
|
69
|
+
if (!key)
|
70
|
+
throw new TypeError(
|
71
|
+
"No key specified."
|
72
|
+
);
|
73
|
+
if (value === undefined)
|
74
|
+
throw new TypeError(
|
75
|
+
"No value specified."
|
76
|
+
);
|
77
|
+
return arbitrate("set", {
|
78
|
+
stringify: false,
|
79
|
+
id: key,
|
80
|
+
data: value,
|
81
|
+
ops: ops || {},
|
82
|
+
});
|
83
|
+
},
|
84
|
+
|
85
|
+
/**
|
86
|
+
* This function adds a number to a key in the database. (If no existing number, it will add to 0)
|
87
|
+
* @param {key} input any string as a key. Also allows for dot notation following the key.
|
88
|
+
* @param {options} [input={ target: null }] Any options to be added to the request.
|
89
|
+
* @returns {data} the updated data.
|
90
|
+
*/
|
91
|
+
|
92
|
+
add: function (key, value, ops) {
|
93
|
+
if (!key)
|
94
|
+
throw new TypeError(
|
95
|
+
"No key specified."
|
96
|
+
);
|
97
|
+
if (isNaN(value))
|
98
|
+
throw new TypeError(
|
99
|
+
"Must specify value to add."
|
100
|
+
);
|
101
|
+
return arbitrate("add", { id: key, data: value, ops: ops || {} });
|
102
|
+
},
|
103
|
+
|
104
|
+
/**
|
105
|
+
* This function subtracts a number to a key in the database. (If no existing number, it will subtract from 0)
|
106
|
+
* @param {key} input any string as a key. Also allows for dot notation following the key.
|
107
|
+
* @param {options} [input={ target: null }] Any options to be added to the request.
|
108
|
+
* @returns {data} the updated data.
|
109
|
+
*/
|
110
|
+
|
111
|
+
subtract: function (key, value, ops) {
|
112
|
+
if (!key)
|
113
|
+
throw new TypeError(
|
114
|
+
"No key specified."
|
115
|
+
);
|
116
|
+
if (isNaN(value))
|
117
|
+
throw new TypeError(
|
118
|
+
"Must specify value to add."
|
119
|
+
);
|
120
|
+
return arbitrate("subtract", { id: key, data: value, ops: ops || {} });
|
121
|
+
},
|
122
|
+
|
123
|
+
/**
|
124
|
+
* This function will push into an array in the database based on the key. (If no existing array, it will create one)
|
125
|
+
* @param {key} input any string as a key. Also allows for dot notation following the key.
|
126
|
+
* @param {options} [input={ target: null }] Any options to be added to the request.
|
127
|
+
* @returns {data} the updated data.
|
128
|
+
*/
|
129
|
+
|
130
|
+
push: function (key, value, ops) {
|
131
|
+
if (!key)
|
132
|
+
throw new TypeError(
|
133
|
+
"No key specified."
|
134
|
+
);
|
135
|
+
if (!value && value != 0)
|
136
|
+
throw new TypeError(
|
137
|
+
"Must specify value to push."
|
138
|
+
);
|
139
|
+
return arbitrate("push", {
|
140
|
+
stringify: true,
|
141
|
+
id: key,
|
142
|
+
data: value,
|
143
|
+
ops: ops || {},
|
144
|
+
});
|
145
|
+
},
|
146
|
+
|
147
|
+
/**
|
148
|
+
|
149
|
+
*/
|
150
|
+
|
151
|
+
/**
|
152
|
+
* This function will delete an object (or property) in the database.
|
153
|
+
* @param {key} input any string as a key. Also allows for dot notation following the key, this will delete the prop in the object.
|
154
|
+
* @param {options} [input={ target: null }] Any options to be added to the request.
|
155
|
+
* @returns {boolean} if it was a success or not.
|
156
|
+
*/
|
157
|
+
|
158
|
+
delete: function (key, ops) {
|
159
|
+
if (!key)
|
160
|
+
throw new TypeError(
|
161
|
+
"No key specified."
|
162
|
+
);
|
163
|
+
return arbitrate("delete", { id: key, ops: ops || {} });
|
164
|
+
},
|
165
|
+
|
166
|
+
/**
|
167
|
+
* This function returns a boolean indicating whether an element with the specified key exists or not.
|
168
|
+
* @param {key} input any string as a key. Also allows for dot notation following the key, this will return if the prop exists or not.
|
169
|
+
* @param {options} [input={ target: null }] Any options to be added to the request.
|
170
|
+
* @returns {boolean} if it exists.
|
171
|
+
*/
|
172
|
+
|
173
|
+
has: function (key, ops) {
|
174
|
+
if (!key)
|
175
|
+
throw new TypeError(
|
176
|
+
"No key specified."
|
177
|
+
);
|
178
|
+
return arbitrate("has", { id: key, ops: ops || {} });
|
179
|
+
},
|
180
|
+
|
181
|
+
includes: function (key, ops) {
|
182
|
+
if (!key)
|
183
|
+
throw new TypeError(
|
184
|
+
"No key specified."
|
185
|
+
);
|
186
|
+
return arbitrate("has", { id: key, ops: ops || {} });
|
187
|
+
},
|
188
|
+
|
189
|
+
/**
|
190
|
+
* This function fetches the entire active table
|
191
|
+
* @param {options} [input={ target: null }] Any options to be added to the request.
|
192
|
+
* @returns {boolean} if it exists.
|
193
|
+
*/
|
194
|
+
|
195
|
+
all: function (ops) {
|
196
|
+
return arbitrate("all", { ops: ops || {} });
|
197
|
+
},
|
198
|
+
|
199
|
+
fetchAll: function (ops) {
|
200
|
+
return arbitrate("all", { ops: ops || {} });
|
201
|
+
},
|
202
|
+
|
203
|
+
/*
|
204
|
+
* Used to get the type of the value.
|
205
|
+
*/
|
206
|
+
|
207
|
+
type: function (key, ops) {
|
208
|
+
if (!key)
|
209
|
+
throw new TypeError(
|
210
|
+
"No key specified."
|
211
|
+
);
|
212
|
+
return arbitrate("type", { id: key, ops: ops || {} });
|
213
|
+
},
|
214
|
+
|
215
|
+
/**
|
216
|
+
* Using 'new' on this function creates a new instance of a table.
|
217
|
+
* @param {name} input any string as the name of the table.
|
218
|
+
* @param {options} options.
|
219
|
+
*/
|
220
|
+
|
221
|
+
table: function (tableName, options = {}) {
|
222
|
+
// Set Name
|
223
|
+
if (typeof tableName !== "string")
|
224
|
+
throw new TypeError(
|
225
|
+
"Table name has to be a string."
|
226
|
+
);
|
227
|
+
else if (tableName.includes(" "))
|
228
|
+
throw new TypeError(
|
229
|
+
"Table name cannot include spaces."
|
230
|
+
);
|
231
|
+
this.tableName = tableName;
|
232
|
+
|
233
|
+
// Methods
|
234
|
+
this.fetch = function (key, ops) {
|
235
|
+
if (!key)
|
236
|
+
throw new TypeError(
|
237
|
+
"No key specified."
|
238
|
+
);
|
239
|
+
return arbitrate(
|
240
|
+
"fetch",
|
241
|
+
{ id: key, ops: ops || {} },
|
242
|
+
this.tableName
|
243
|
+
);
|
244
|
+
};
|
245
|
+
|
246
|
+
this.get = function (key, ops) {
|
247
|
+
if (!key)
|
248
|
+
throw new TypeError(
|
249
|
+
"No key specified."
|
250
|
+
);
|
251
|
+
return arbitrate(
|
252
|
+
"fetch",
|
253
|
+
{ id: key, ops: ops || {} },
|
254
|
+
this.tableName
|
255
|
+
);
|
256
|
+
};
|
257
|
+
|
258
|
+
this.set = function (key, value, ops) {
|
259
|
+
if (!key)
|
260
|
+
throw new TypeError(
|
261
|
+
"No key specified."
|
262
|
+
);
|
263
|
+
if (!value && value != 0)
|
264
|
+
throw new TypeError(
|
265
|
+
"No value specified."
|
266
|
+
);
|
267
|
+
return arbitrate(
|
268
|
+
"set",
|
269
|
+
{ stringify: true, id: key, data: value, ops: ops || {} },
|
270
|
+
this.tableName
|
271
|
+
);
|
272
|
+
};
|
273
|
+
|
274
|
+
this.add = function (key, value, ops) {
|
275
|
+
if (!key)
|
276
|
+
throw new TypeError(
|
277
|
+
"No key specified."
|
278
|
+
);
|
279
|
+
if (isNaN(value))
|
280
|
+
throw new TypeError(
|
281
|
+
"Must specify value to add."
|
282
|
+
);
|
283
|
+
return arbitrate(
|
284
|
+
"add",
|
285
|
+
{ id: key, data: value, ops: ops || {} },
|
286
|
+
this.tableName
|
287
|
+
);
|
288
|
+
};
|
289
|
+
|
290
|
+
this.subtract = function (key, value, ops) {
|
291
|
+
if (!key)
|
292
|
+
throw new TypeError(
|
293
|
+
"No key specified."
|
294
|
+
);
|
295
|
+
if (isNaN(value))
|
296
|
+
throw new TypeError(
|
297
|
+
"Must specify value to add."
|
298
|
+
);
|
299
|
+
return arbitrate(
|
300
|
+
"subtract",
|
301
|
+
{ id: key, data: value, ops: ops || {} },
|
302
|
+
this.tableName
|
303
|
+
);
|
304
|
+
};
|
305
|
+
|
306
|
+
this.push = function (key, value, ops) {
|
307
|
+
if (!key)
|
308
|
+
throw new TypeError(
|
309
|
+
"No key specified."
|
310
|
+
);
|
311
|
+
if (!value && value != 0)
|
312
|
+
throw new TypeError(
|
313
|
+
"Must specify value to push."
|
314
|
+
);
|
315
|
+
return arbitrate(
|
316
|
+
"push",
|
317
|
+
{ stringify: true, id: key, data: value, ops: ops || {} },
|
318
|
+
this.tableName
|
319
|
+
);
|
320
|
+
};
|
321
|
+
|
322
|
+
this.delete = function (key, ops) {
|
323
|
+
if (!key)
|
324
|
+
throw new TypeError(
|
325
|
+
"No key specified."
|
326
|
+
);
|
327
|
+
return arbitrate(
|
328
|
+
"delete",
|
329
|
+
{ id: key, ops: ops || {} },
|
330
|
+
this.tableName
|
331
|
+
);
|
332
|
+
};
|
333
|
+
|
334
|
+
this.has = function (key, ops) {
|
335
|
+
if (!key)
|
336
|
+
throw new TypeError(
|
337
|
+
"No key specified."
|
338
|
+
);
|
339
|
+
return arbitrate(
|
340
|
+
"has",
|
341
|
+
{ id: key, ops: ops || {} },
|
342
|
+
this.tableName
|
343
|
+
);
|
344
|
+
};
|
345
|
+
|
346
|
+
this.includes = function (key, ops) {
|
347
|
+
if (!key)
|
348
|
+
throw new TypeError(
|
349
|
+
"No key specified."
|
350
|
+
);
|
351
|
+
return arbitrate(
|
352
|
+
"has",
|
353
|
+
{ id: key, ops: ops || {} },
|
354
|
+
this.tableName
|
355
|
+
);
|
356
|
+
};
|
357
|
+
|
358
|
+
this.fetchAll = function (ops) {
|
359
|
+
return arbitrate("all", { ops: ops || {} }, this.tableName);
|
360
|
+
};
|
361
|
+
|
362
|
+
this.all = function (ops) {
|
363
|
+
return arbitrate("all", { ops: ops || {} }, this.tableName);
|
364
|
+
};
|
365
|
+
},
|
366
|
+
};
|
367
|
+
|
368
|
+
function arbitrate(method, params, tableName) {
|
369
|
+
// Configure Options
|
370
|
+
let options = {table: tableName || params.ops.table || "json",};
|
371
|
+
|
372
|
+
// Access Database
|
373
|
+
db.prepare(`CREATE TABLE IF NOT EXISTS ${options.table} (ID TEXT, json TEXT)`).run();
|
374
|
+
|
375
|
+
// Verify Options
|
376
|
+
if (params.ops.target && params.ops.target[0] === ".") params.ops.target = params.ops.target.slice(1); // Remove prefix if necessary
|
377
|
+
if (params.data && params.data === Infinity) throw new TypeError(`You cannot set Infinity into the database @ ID: ${params.id}`);
|
378
|
+
|
379
|
+
// Stringify
|
380
|
+
// if (params.stringify) {
|
381
|
+
// try {
|
382
|
+
// params.data = JSON.stringify(params.data);
|
383
|
+
// } catch (e) {
|
384
|
+
// throw new TypeError(
|
385
|
+
// `Please supply a valid input @ ID: ${params.id}\nError: ${e.message}`
|
386
|
+
// );
|
387
|
+
// }
|
388
|
+
// }
|
389
|
+
|
390
|
+
// Translate dot notation from keys
|
391
|
+
if (params.id && typeof params.id == "string" && params.id.includes(".")) {
|
392
|
+
let unparsed = params.id.split(".");
|
393
|
+
params.id = unparsed.shift();
|
394
|
+
params.ops.target = unparsed.join(".");
|
395
|
+
}
|
396
|
+
|
397
|
+
// Run & Return Method
|
398
|
+
return methods[method](db, params, options);
|
399
|
+
}
|