cradova 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/LICENSE +201 -0
- package/cradova.png +0 -0
- package/docs/README.md +0 -0
- package/index.d.ts +52 -0
- package/index.js +342 -0
- package/index.ts +366 -0
- package/package.json +36 -0
- package/scripts/JsonDB.d.ts +298 -0
- package/scripts/JsonDB.js +698 -0
- package/scripts/JsonDB.ts +794 -0
- package/scripts/Metrics.d.ts +51 -0
- package/scripts/Metrics.js +56 -0
- package/scripts/Metrics.ts +66 -0
- package/scripts/Router.d.ts +12 -0
- package/scripts/Router.js +95 -0
- package/scripts/Router.ts +105 -0
- package/scripts/Screen.d.ts +11 -0
- package/scripts/Screen.js +62 -0
- package/scripts/Screen.ts +62 -0
- package/scripts/animate.d.ts +25 -0
- package/scripts/animate.js +47 -0
- package/scripts/animate.ts +57 -0
- package/scripts/css.d.ts +20 -0
- package/scripts/css.js +41 -0
- package/scripts/css.ts +46 -0
- package/scripts/dispatcher.d.ts +1 -0
- package/scripts/dispatcher.js +57 -0
- package/scripts/dispatcher.ts +58 -0
- package/scripts/file-system.d.ts +2 -0
- package/scripts/file-system.js +175 -0
- package/scripts/file-system.ts +177 -0
- package/scripts/fullscreen.d.ts +4 -0
- package/scripts/fullscreen.js +29 -0
- package/scripts/fullscreen.ts +30 -0
- package/scripts/init.d.ts +2 -0
- package/scripts/init.js +17 -0
- package/scripts/init.ts +18 -0
- package/scripts/localStorage.d.ts +9 -0
- package/scripts/localStorage.js +26 -0
- package/scripts/localStorage.ts +37 -0
- package/scripts/media.d.ts +22 -0
- package/scripts/media.js +48 -0
- package/scripts/media.ts +51 -0
- package/scripts/reuse.ts +74 -0
- package/scripts/speaker.d.ts +2 -0
- package/scripts/speaker.js +16 -0
- package/scripts/speaker.ts +25 -0
- package/scripts/store.d.ts +10 -0
- package/scripts/store.js +56 -0
- package/scripts/store.ts +47 -0
- package/scripts/swipe.d.ts +9 -0
- package/scripts/swipe.js +113 -0
- package/scripts/swipe.ts +129 -0
- package/scripts/widget.d.ts +2 -0
- package/scripts/widget.js +19 -0
- package/scripts/widget.ts +23 -0
- package/service-worker.d.ts +2 -0
- package/service-worker.js +40 -0
- package/service-worker.ts +52 -0
- package/tsconfig.json +11 -0
package/index.ts
ADDED
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
/* _____
|
|
2
|
+
* / \
|
|
3
|
+
* / /\ \
|
|
4
|
+
* / / \__\
|
|
5
|
+
* / / _ _
|
|
6
|
+
* / / (_) (_)
|
|
7
|
+
* ( \ ___
|
|
8
|
+
* \ \ / /
|
|
9
|
+
* \ \/ /
|
|
10
|
+
* \ /
|
|
11
|
+
* \____/
|
|
12
|
+
*
|
|
13
|
+
* Cradova FrameWork
|
|
14
|
+
* @version 1.0.0
|
|
15
|
+
@licence Apache v2
|
|
16
|
+
|
|
17
|
+
@publisher : Friday Candour;
|
|
18
|
+
@project : Cradova Framework;
|
|
19
|
+
@copyright-lincense : Apache v2;
|
|
20
|
+
email > fridaymaxtour@gmail.com
|
|
21
|
+
github > www.github.com/FridayCandour
|
|
22
|
+
telegram > @uiedbooker
|
|
23
|
+
|
|
24
|
+
Apache License
|
|
25
|
+
Version 2.0, January 2004
|
|
26
|
+
http://www.apache.org/licenses/
|
|
27
|
+
|
|
28
|
+
* Copyright 2022 Friday Candour. All Rights Reserved.
|
|
29
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
30
|
+
* you may not use this file except in compliance with the License.
|
|
31
|
+
* You may obtain a copy of the License at
|
|
32
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
33
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
34
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
35
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
36
|
+
* See the License for the specific language governing permissions and
|
|
37
|
+
* limitations under the License.
|
|
38
|
+
*
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
import css from "./scripts/css.js";
|
|
42
|
+
import w from "./scripts/widget.js";
|
|
43
|
+
import Init from "./scripts/init.js";
|
|
44
|
+
import swipe from "./scripts/swipe.js";
|
|
45
|
+
import media from "./scripts/media.js";
|
|
46
|
+
import Store from "./scripts/store.js";
|
|
47
|
+
import Router from "./scripts/Router.js";
|
|
48
|
+
import Screen from "./scripts/Screen.js";
|
|
49
|
+
import JSONDB from "./scripts/JsonDB.js";
|
|
50
|
+
import Speaker from "./scripts/speaker.js";
|
|
51
|
+
import animate from "./scripts/animate.js";
|
|
52
|
+
import fs from "./scripts/file-system.js";
|
|
53
|
+
import ls from "./scripts/localStorage.js";
|
|
54
|
+
import dispatch from "./scripts/dispatcher.js";
|
|
55
|
+
import fullScreen from "./scripts/fullscreen.js";
|
|
56
|
+
import metrics from "./scripts/Metrics.js";
|
|
57
|
+
|
|
58
|
+
("use strict");
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Acts as a function or object depending on how it is referenced.
|
|
62
|
+
*
|
|
63
|
+
* :: schemes
|
|
64
|
+
* @example
|
|
65
|
+
* // creating html elements
|
|
66
|
+
* @param element_initials | <html template string, props object?, children?>.
|
|
67
|
+
* @returns Cradova element base function.
|
|
68
|
+
* @example
|
|
69
|
+
* // html template strings examples
|
|
70
|
+
*
|
|
71
|
+
* //template literals example, can't accept props object or children
|
|
72
|
+
*
|
|
73
|
+
* _`p| am a p tag`
|
|
74
|
+
* // equivilent <p> am a p tag</p>
|
|
75
|
+
*
|
|
76
|
+
* or _`p.class| am a p tag`
|
|
77
|
+
* // equivilent <p class="class"> am a p tag </p>
|
|
78
|
+
*
|
|
79
|
+
* or _`p#id| am a p tag`
|
|
80
|
+
* // equivilent <p id="id"> am a p tag </p>
|
|
81
|
+
*
|
|
82
|
+
* or _`p.class#id| am a p tag`
|
|
83
|
+
* // equivilent <p id="id" class="class"> am a p tag </p>
|
|
84
|
+
*
|
|
85
|
+
* // using props and children
|
|
86
|
+
*
|
|
87
|
+
* _("p| am a p tag" ,{
|
|
88
|
+
* //props like
|
|
89
|
+
* text: "am a dynamic paragraph tag", // this will override text value above
|
|
90
|
+
* style: {
|
|
91
|
+
* color: "blue"
|
|
92
|
+
* }
|
|
93
|
+
* },
|
|
94
|
+
* // place other children here like span
|
|
95
|
+
* _`span| am a span tag like so`,
|
|
96
|
+
* _("span| am a span tag like so", {style: {color: "brown"}})
|
|
97
|
+
* )
|
|
98
|
+
*
|
|
99
|
+
* every other cradova methods like _.dispatch, _.reuse ... can be distructured
|
|
100
|
+
* vist the docs for more info.
|
|
101
|
+
* Enjoy!
|
|
102
|
+
*/
|
|
103
|
+
|
|
104
|
+
const _ = (...element_initials: { raw: any }[]) => {
|
|
105
|
+
let properties: { [x: string]: any },
|
|
106
|
+
childrens: string | any[] = [];
|
|
107
|
+
// getting props and children set
|
|
108
|
+
if (
|
|
109
|
+
typeof element_initials[1] == "object" &&
|
|
110
|
+
!(element_initials[1] instanceof HTMLElement)
|
|
111
|
+
) {
|
|
112
|
+
properties = element_initials[1];
|
|
113
|
+
if (element_initials.length > 2) {
|
|
114
|
+
childrens = element_initials.slice(2, element_initials.length);
|
|
115
|
+
}
|
|
116
|
+
} else {
|
|
117
|
+
if (
|
|
118
|
+
element_initials[1] instanceof HTMLElement ||
|
|
119
|
+
typeof element_initials[1] === "function"
|
|
120
|
+
) {
|
|
121
|
+
childrens = element_initials.slice(1, element_initials.length);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// don't move this up
|
|
125
|
+
if (typeof element_initials[0] === "string") {
|
|
126
|
+
element_initials = element_initials[0];
|
|
127
|
+
}
|
|
128
|
+
// verifing the children array
|
|
129
|
+
for (let i = 0; i < childrens.length; i++) {
|
|
130
|
+
if (
|
|
131
|
+
!(childrens[i] instanceof HTMLElement) &&
|
|
132
|
+
typeof childrens[i] !== "function"
|
|
133
|
+
) {
|
|
134
|
+
throw new Error(
|
|
135
|
+
"cradova err invalid children list, should be a Cradova element base " +
|
|
136
|
+
childrens[i]
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* sorts props and creates cradova element base
|
|
142
|
+
* @param element_initials
|
|
143
|
+
* @returns cradova element base
|
|
144
|
+
*/
|
|
145
|
+
function identify(element_initials: any[]) {
|
|
146
|
+
if (typeof element_initials !== "object") {
|
|
147
|
+
element_initials = [element_initials];
|
|
148
|
+
}
|
|
149
|
+
// getting element id, class and text value if available
|
|
150
|
+
let tag, className, ID;
|
|
151
|
+
const [el, innerValue] = element_initials[0].split("|");
|
|
152
|
+
|
|
153
|
+
if (el.indexOf("#") > -1) {
|
|
154
|
+
ID = el.split("#")[1];
|
|
155
|
+
tag = el.split("#")[0];
|
|
156
|
+
className = ID.split(".")[1];
|
|
157
|
+
if (className) {
|
|
158
|
+
ID = ID.split(".")[0];
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (el.indexOf(".") > -1) {
|
|
163
|
+
if (!className) {
|
|
164
|
+
className = el.split(".")[1];
|
|
165
|
+
tag = el.split(".")[0];
|
|
166
|
+
let locID = className.split("#")[1];
|
|
167
|
+
if (locID) {
|
|
168
|
+
className = className.split("#")[0];
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (tag === "") {
|
|
174
|
+
tag = "div";
|
|
175
|
+
}
|
|
176
|
+
if (!tag && tag !== "") {
|
|
177
|
+
tag = el;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const initials = { tag, className, ID, innerValue };
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* params [incoming]:any elements and props object
|
|
184
|
+
* @returns HTML element
|
|
185
|
+
*/
|
|
186
|
+
|
|
187
|
+
return (...incoming: string | any[]) => {
|
|
188
|
+
let childrens2rd = [],
|
|
189
|
+
props = {},
|
|
190
|
+
text;
|
|
191
|
+
|
|
192
|
+
for (let i = 0; i < incoming.length; i++) {
|
|
193
|
+
if (
|
|
194
|
+
typeof incoming[i] === "function" ||
|
|
195
|
+
incoming[i] instanceof HTMLElement
|
|
196
|
+
) {
|
|
197
|
+
childrens2rd.push(incoming[i]);
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
//
|
|
201
|
+
if (
|
|
202
|
+
!(incoming[i] instanceof HTMLElement) &&
|
|
203
|
+
typeof incoming[i] === "object"
|
|
204
|
+
) {
|
|
205
|
+
props = incoming[i];
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
if (typeof incoming[i] === "string") {
|
|
209
|
+
text = incoming[i];
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
//
|
|
213
|
+
if (childrens[0]) {
|
|
214
|
+
if (childrens2rd) {
|
|
215
|
+
childrens2rd.push(...childrens);
|
|
216
|
+
} else {
|
|
217
|
+
childrens2rd = childrens;
|
|
218
|
+
}
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const element = document.createElement(initials.tag);
|
|
224
|
+
if (initials.className) {
|
|
225
|
+
element.className = initials.className;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (initials.ID) {
|
|
229
|
+
element.id = initials.ID;
|
|
230
|
+
}
|
|
231
|
+
if (initials.innerValue) {
|
|
232
|
+
element.append(initials.innerValue);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
for (const prop in properties) {
|
|
236
|
+
if (prop === "style") {
|
|
237
|
+
for (const [k, v] of Object.entries(properties[prop])) {
|
|
238
|
+
element.style[k] = v;
|
|
239
|
+
}
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
if (prop === "class") {
|
|
243
|
+
element.classList.add(properties[prop]);
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
if (prop === "text") {
|
|
247
|
+
element.innerText = properties[prop];
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
element[prop] = properties[prop];
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// over-rides props that appear in the first level
|
|
254
|
+
|
|
255
|
+
if (props && typeof props === "object" && !Array.isArray(props)) {
|
|
256
|
+
for (const prop in props) {
|
|
257
|
+
if (prop === "style") {
|
|
258
|
+
for (const [k, v] of Object.entries(props[prop])) {
|
|
259
|
+
element.style[k] = v;
|
|
260
|
+
}
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
if (prop === "text") {
|
|
264
|
+
element.innerText = props[prop];
|
|
265
|
+
continue;
|
|
266
|
+
}
|
|
267
|
+
if (prop === "class") {
|
|
268
|
+
element.classList.add(props[prop]);
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
if (prop === "fullscreen") {
|
|
272
|
+
if (properties[prop]) {
|
|
273
|
+
fullScreen(element).set();
|
|
274
|
+
} else {
|
|
275
|
+
fullScreen(element).exist();
|
|
276
|
+
}
|
|
277
|
+
continue;
|
|
278
|
+
}
|
|
279
|
+
element[prop] = props[prop];
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
// building parent tree if children are available
|
|
283
|
+
if (childrens2rd && childrens2rd[0]) {
|
|
284
|
+
for (let i = 0; i < childrens2rd.length; i++) {
|
|
285
|
+
if (typeof childrens2rd[i] === "function") {
|
|
286
|
+
element.append(childrens2rd[i]());
|
|
287
|
+
continue;
|
|
288
|
+
}
|
|
289
|
+
element.append(childrens2rd[i]);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
// adds text content if available
|
|
293
|
+
if (text) {
|
|
294
|
+
element.append(text);
|
|
295
|
+
}
|
|
296
|
+
if (element.stateID) {
|
|
297
|
+
// adding cradova dynamic state signature as class name
|
|
298
|
+
element.classList.add("cra_child_doc");
|
|
299
|
+
}
|
|
300
|
+
return element;
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
if (element_initials[0].raw) {
|
|
304
|
+
element_initials = identify(element_initials[0].raw);
|
|
305
|
+
} else {
|
|
306
|
+
element_initials = identify(element_initials);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
return element_initials;
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
_.register = (name: any) => {
|
|
313
|
+
for (const key in name) {
|
|
314
|
+
_[key] = name[key];
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* registering added methods to the cradova object _
|
|
320
|
+
*
|
|
321
|
+
* these can be safely destructured to use alone
|
|
322
|
+
*/
|
|
323
|
+
_.register({
|
|
324
|
+
w,
|
|
325
|
+
css,
|
|
326
|
+
Init,
|
|
327
|
+
media,
|
|
328
|
+
swipe,
|
|
329
|
+
Store,
|
|
330
|
+
JSONDB,
|
|
331
|
+
Screen,
|
|
332
|
+
Router,
|
|
333
|
+
LS: ls,
|
|
334
|
+
FS: fs,
|
|
335
|
+
Speaker,
|
|
336
|
+
metrics,
|
|
337
|
+
animate,
|
|
338
|
+
dispatch,
|
|
339
|
+
// App: window.app,
|
|
340
|
+
globalState: { state: {}, stateID: "" },
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
_.Init();
|
|
344
|
+
window._ = _;
|
|
345
|
+
|
|
346
|
+
export default _;
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
*
|
|
350
|
+
* Registering ServiceWorker
|
|
351
|
+
*
|
|
352
|
+
* */
|
|
353
|
+
window.addEventListener("load", async () => {
|
|
354
|
+
if ("serviceWorker" in navigator) {
|
|
355
|
+
await navigator.serviceWorker
|
|
356
|
+
.register("service-worker.js")
|
|
357
|
+
.then(function (registration) {
|
|
358
|
+
// Registration was successful
|
|
359
|
+
// console.log(
|
|
360
|
+
// `Service Worker registration successful. Scope: ${registration.scope}
|
|
361
|
+
// comment this line out at nodemodules/cradova/index.js line 362`
|
|
362
|
+
// );
|
|
363
|
+
})
|
|
364
|
+
.catch((err) => console.log(err));
|
|
365
|
+
}
|
|
366
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "cradova",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Web framework for building web apps and PWAs",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"directories": {
|
|
7
|
+
"doc": "docs"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/FridayCandour/cradova.git"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"framework",
|
|
18
|
+
"javascript",
|
|
19
|
+
"typescript",
|
|
20
|
+
"web",
|
|
21
|
+
"app",
|
|
22
|
+
"PWA",
|
|
23
|
+
"android",
|
|
24
|
+
"IOS",
|
|
25
|
+
"windows",
|
|
26
|
+
"linux",
|
|
27
|
+
"mac"
|
|
28
|
+
],
|
|
29
|
+
"author": "fridaycandour",
|
|
30
|
+
"license": "Apache-2.0",
|
|
31
|
+
"types": "./index.d.ts",
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/FridayCandour/cradova/issues"
|
|
34
|
+
},
|
|
35
|
+
"homepage": "https://github.com/FridayCandour/cradova#readme"
|
|
36
|
+
}
|
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON DB DataBase MIT Licence © 2022
|
|
3
|
+
* ************************************
|
|
4
|
+
* Created by Friday Candour @uiedbooker
|
|
5
|
+
* email > fridaymaxtour@gmail.com
|
|
6
|
+
* github > www.github.com/FridayCandour
|
|
7
|
+
* telegram > @uiedbooker
|
|
8
|
+
* JSONDB @version 1.0.0
|
|
9
|
+
* */
|
|
10
|
+
export declare const JSONDBversion = "1.0.0";
|
|
11
|
+
declare class JSONDBTableWrapper {
|
|
12
|
+
put: (name: string, value: any) => Promise<void>;
|
|
13
|
+
get: (name: string) => Promise<unknown>;
|
|
14
|
+
validator: (incoming: {
|
|
15
|
+
[x: string]: any;
|
|
16
|
+
}, tables: string | any[]) => {};
|
|
17
|
+
self: any;
|
|
18
|
+
keys: any;
|
|
19
|
+
constructor(self: unknown, keys: any);
|
|
20
|
+
/**
|
|
21
|
+
* Save with relations
|
|
22
|
+
* ---------------------
|
|
23
|
+
* @type .saveWithRelations(target table, schema, schema | schema[]) => Promise(object)
|
|
24
|
+
* @example
|
|
25
|
+
* // single relation
|
|
26
|
+
await PollTable.saveWithRelations(MessageTable, Poll, message);
|
|
27
|
+
// arrays of relations
|
|
28
|
+
await PollTable.saveWithRelations(MessageTable, Poll, allMessages);
|
|
29
|
+
*/
|
|
30
|
+
saveWithRelations(table: {
|
|
31
|
+
self: {
|
|
32
|
+
name: string | number;
|
|
33
|
+
};
|
|
34
|
+
}, incoming: {
|
|
35
|
+
index: string | number;
|
|
36
|
+
}, relations: string | any[]): Promise<any>;
|
|
37
|
+
/**
|
|
38
|
+
* Save table into a Jsondb instance
|
|
39
|
+
* -----------------------------
|
|
40
|
+
* @type .save(schema)=> Promise(object)
|
|
41
|
+
* @example
|
|
42
|
+
await PollTable.save(poll)
|
|
43
|
+
*/
|
|
44
|
+
save(incoming: {
|
|
45
|
+
index: number;
|
|
46
|
+
relations: {};
|
|
47
|
+
}): Promise<{
|
|
48
|
+
index: number;
|
|
49
|
+
relations: {};
|
|
50
|
+
}>;
|
|
51
|
+
/**
|
|
52
|
+
* Save table into a Jsondb instance
|
|
53
|
+
* -----------------------------
|
|
54
|
+
* @type .remove(schema)=> Promise(object)
|
|
55
|
+
* @example
|
|
56
|
+
await PollTable.remove(poll)
|
|
57
|
+
*/
|
|
58
|
+
remove(entity: {
|
|
59
|
+
index: string | number;
|
|
60
|
+
}): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* Save table into a Jsondb instance
|
|
63
|
+
* -----------------------------
|
|
64
|
+
* @type .count(schema)=> Promise(number)
|
|
65
|
+
* @example
|
|
66
|
+
await PollTable.count(poll)
|
|
67
|
+
*/
|
|
68
|
+
count(): Promise<any>;
|
|
69
|
+
/**
|
|
70
|
+
* Save table into a Jsondb instance
|
|
71
|
+
* -----------------------------
|
|
72
|
+
* @type .getAll()=> Promise(object[])
|
|
73
|
+
* @example
|
|
74
|
+
await PollTable.getAll()
|
|
75
|
+
*/
|
|
76
|
+
getAll(): Promise<any>;
|
|
77
|
+
/**
|
|
78
|
+
* get entities with any of the values specifiled from a Jsondb instance
|
|
79
|
+
* -----------------------------
|
|
80
|
+
* @type .getWhereAny({prop: value}, number | undefind)=> Promise(object)
|
|
81
|
+
* @example
|
|
82
|
+
await PollTable.getWhereAny({name: "friday", age: 121, class: "senior"}) // gets all
|
|
83
|
+
await PollTable.getWhereAny({email: "fridaymaxtour@gmail.com"}, 2) // gets 2 if they are up to two
|
|
84
|
+
*/
|
|
85
|
+
getWhereAny(props: {
|
|
86
|
+
[s: string]: unknown;
|
|
87
|
+
} | ArrayLike<unknown>, number: number): Promise<any[]>;
|
|
88
|
+
/**
|
|
89
|
+
* get entities with the given prop of type "string" where the values specifiled is included
|
|
90
|
+
* -----------------------------
|
|
91
|
+
* @type .getWhereAnyPropsIncludes({prop: value}, number | undefind)=> Promise(object)
|
|
92
|
+
*
|
|
93
|
+
* @example prop must be type string!
|
|
94
|
+
*
|
|
95
|
+
await PollTable.getWhereAnyPropsIncludes({name: "fri"}) // gets all
|
|
96
|
+
await PollTable.getWhereAnyPropsIncludes({name: "fri"}, 2) // gets 2 if they are up to two
|
|
97
|
+
*/
|
|
98
|
+
getWhereAnyPropsIncludes(props: {
|
|
99
|
+
[s: string]: unknown;
|
|
100
|
+
} | ArrayLike<unknown>, number: number): Promise<any[]>;
|
|
101
|
+
/**
|
|
102
|
+
* get an entity with the values specifiled from a Jsondb instance
|
|
103
|
+
* -----------------------------
|
|
104
|
+
* @type .getOne({prop: value})=> Promise(object)
|
|
105
|
+
* @example
|
|
106
|
+
|
|
107
|
+
await PollTable.getOne({email: "fridaymaxtour@gamail.com"}) // gets one
|
|
108
|
+
|
|
109
|
+
*/
|
|
110
|
+
getOne(props: {
|
|
111
|
+
[s: string]: unknown;
|
|
112
|
+
} | ArrayLike<unknown>): Promise<any>;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Create a new JSONDB object
|
|
116
|
+
*------------------------
|
|
117
|
+
* @class
|
|
118
|
+
|
|
119
|
+
* const database = new JSONDB()
|
|
120
|
+
*
|
|
121
|
+
* Creates a new JSONDB object
|
|
122
|
+
*
|
|
123
|
+
* .
|
|
124
|
+
* */
|
|
125
|
+
declare class JSONDB {
|
|
126
|
+
DB_NAME: string;
|
|
127
|
+
username: string;
|
|
128
|
+
encrypted: boolean;
|
|
129
|
+
initialised: boolean;
|
|
130
|
+
time_created: string;
|
|
131
|
+
version: string;
|
|
132
|
+
last_access_time: string;
|
|
133
|
+
visuality: string;
|
|
134
|
+
Entities: {};
|
|
135
|
+
tables: {};
|
|
136
|
+
password: string;
|
|
137
|
+
constructor();
|
|
138
|
+
getDB(name: string): Promise<unknown>;
|
|
139
|
+
/**
|
|
140
|
+
* Schema constructor for Jsondb
|
|
141
|
+
* -----------------------------
|
|
142
|
+
*
|
|
143
|
+
* name @type string
|
|
144
|
+
*
|
|
145
|
+
* columns @type object {
|
|
146
|
+
*
|
|
147
|
+
* type > @type any of number > string > boolean > blob and must be specified
|
|
148
|
+
*
|
|
149
|
+
* nullable @type bolean true > false default false
|
|
150
|
+
*
|
|
151
|
+
* unique @type bolean true > false default false
|
|
152
|
+
*
|
|
153
|
+
* }
|
|
154
|
+
*
|
|
155
|
+
* relations @type object {
|
|
156
|
+
*
|
|
157
|
+
* target: entity schema @type object,
|
|
158
|
+
*
|
|
159
|
+
* attachment_name: @type string,
|
|
160
|
+
*
|
|
161
|
+
* type : @type string should be "many" or "one"
|
|
162
|
+
*
|
|
163
|
+
* }
|
|
164
|
+
*
|
|
165
|
+
*
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
*
|
|
169
|
+
* const MessageSchema = database.schema({
|
|
170
|
+
name: "Message",
|
|
171
|
+
columns: {
|
|
172
|
+
vote: {
|
|
173
|
+
type: "number",
|
|
174
|
+
},
|
|
175
|
+
time: {
|
|
176
|
+
type: "string",
|
|
177
|
+
nullable: true,
|
|
178
|
+
},
|
|
179
|
+
value: {
|
|
180
|
+
type: "string",
|
|
181
|
+
},
|
|
182
|
+
},
|
|
183
|
+
});
|
|
184
|
+
*
|
|
185
|
+
* const PollSchema = new JSONDB.schema({
|
|
186
|
+
name: "Poll",
|
|
187
|
+
columns: {
|
|
188
|
+
value: {
|
|
189
|
+
type: "varchar",
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
relations: {
|
|
193
|
+
Message: {
|
|
194
|
+
target: Message,
|
|
195
|
+
type: "many-to-one",
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
});
|
|
199
|
+
*/
|
|
200
|
+
schema(schema_configuration_object: Record<string, string>): {
|
|
201
|
+
base_name: string;
|
|
202
|
+
name: string;
|
|
203
|
+
last_index: number;
|
|
204
|
+
columns: string;
|
|
205
|
+
relations: string;
|
|
206
|
+
};
|
|
207
|
+
/**
|
|
208
|
+
* Create a new JSONDB instance
|
|
209
|
+
*------------------------
|
|
210
|
+
* @example
|
|
211
|
+
* // creates a JSONDB object
|
|
212
|
+
* const Database = new JSONDB()
|
|
213
|
+
* // database configuration object
|
|
214
|
+
* const config = {
|
|
215
|
+
DB_NAME: "my db",
|
|
216
|
+
password: "password",
|
|
217
|
+
username: "jsondb_username",
|
|
218
|
+
encrypted: false,
|
|
219
|
+
}
|
|
220
|
+
// Creates a new JSONDB instance
|
|
221
|
+
* Database.init(config)
|
|
222
|
+
* */
|
|
223
|
+
init(config: {
|
|
224
|
+
name: string;
|
|
225
|
+
password: string;
|
|
226
|
+
username: string;
|
|
227
|
+
encrypted: boolean;
|
|
228
|
+
}): void;
|
|
229
|
+
/**
|
|
230
|
+
* Create secure connection a Jsondb instance
|
|
231
|
+
* -----------------------------
|
|
232
|
+
* @example
|
|
233
|
+
*
|
|
234
|
+
* const details = {
|
|
235
|
+
password: "password",
|
|
236
|
+
username: "jsondb_username",
|
|
237
|
+
};
|
|
238
|
+
const connection = await database.createJSONDBConnection(details);
|
|
239
|
+
*/
|
|
240
|
+
createJSONDBConnection(details: {
|
|
241
|
+
username: any;
|
|
242
|
+
password: any;
|
|
243
|
+
}): Promise<{
|
|
244
|
+
Entities: any;
|
|
245
|
+
keys: any;
|
|
246
|
+
/**
|
|
247
|
+
* Get a table from JSONDB
|
|
248
|
+
*------------------------
|
|
249
|
+
* @example
|
|
250
|
+
*
|
|
251
|
+
*
|
|
252
|
+
const details = {
|
|
253
|
+
password: "password",
|
|
254
|
+
username: "jsondb_username",
|
|
255
|
+
};
|
|
256
|
+
// getting connection instance into JSONDB
|
|
257
|
+
const connection = await database.createJSONDBConnection(details);
|
|
258
|
+
// getting a table
|
|
259
|
+
const MessageTable = connection.getTable("Message");
|
|
260
|
+
* */
|
|
261
|
+
getTable(table_name: string): JSONDBTableWrapper;
|
|
262
|
+
}>;
|
|
263
|
+
validateRelations(relations: {
|
|
264
|
+
[s: string]: unknown;
|
|
265
|
+
} | ArrayLike<unknown>): void;
|
|
266
|
+
validateColumns(columns: {
|
|
267
|
+
[s: string]: unknown;
|
|
268
|
+
} | ArrayLike<unknown>): void;
|
|
269
|
+
/**
|
|
270
|
+
* Assemble Entities into Jsondb
|
|
271
|
+
* -----------------------------
|
|
272
|
+
* @example
|
|
273
|
+
*
|
|
274
|
+
* const MessageSchema = database.schema({
|
|
275
|
+
name: "Message",
|
|
276
|
+
columns: {
|
|
277
|
+
vote: {
|
|
278
|
+
type: "number",
|
|
279
|
+
},
|
|
280
|
+
time: {
|
|
281
|
+
type: "string",
|
|
282
|
+
nullable: true,
|
|
283
|
+
},
|
|
284
|
+
value: {
|
|
285
|
+
type: "string",
|
|
286
|
+
},
|
|
287
|
+
},
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
database.assemble([MessageSchema]);
|
|
291
|
+
*
|
|
292
|
+
*/
|
|
293
|
+
assemble(allEntities: string | any[]): void;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* @exports
|
|
297
|
+
*/
|
|
298
|
+
export default JSONDB;
|