beanbagdb 0.5.51 → 0.5.52
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/README.md +7 -129
- package/doc-src/0_about.md +115 -0
- package/doc-src/1_getting-started.md +1 -0
- package/doc-src/2_schema.md +1 -0
- package/doc-src/3_plugins.md +1 -0
- package/doc-src/contents.json +15 -0
- package/jsdoc.json +1 -1
- package/package.json +3 -2
- package/src/index.js +804 -437
- package/src/system_schema.js +1 -1
- package/test/operations.test.js +1 -1
- package/test/test1.js +5 -14
- /package/{docs → doc-src}/logo.png +0 -0
package/README.md
CHANGED
|
@@ -1,137 +1,15 @@
|
|
|
1
1
|
# BeanbagDB
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
<img src="./docs/logo.png" alt="Alt text" style="width:auto; height:100px">
|
|
6
|
-
|
|
7
|
-
v 0.0.0
|
|
8
|
-
</div>
|
|
9
|
-
|
|
10
|
-
## The Database architecture
|
|
11
|
-
A BeanbagDB is a collection of JSON documents. In a NoSQL database, documents don't need to follow a specific schema. Typically, the developer defines a schema based on the specific problem the app is intended to solve.
|
|
12
|
-
|
|
13
|
-
While, BeanBagDB allows users to create their own schemas for documents, all document internally share a consistent structure that accommodates the user defined schema.
|
|
14
|
-
|
|
15
|
-
Each document in the database follows this structure :
|
|
16
|
-
```
|
|
17
|
-
{
|
|
18
|
-
_id, _rev
|
|
19
|
-
data : {
|
|
20
|
-
user data
|
|
21
|
-
},
|
|
22
|
-
schema: "name_of_the_schema",
|
|
23
|
-
meta : {},
|
|
24
|
-
}
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
Here, the `data` object contains user's information, while the `schema` defines it's associated structure. The `meta` field holds metadata such as creation and last updated on date and user defined tags.
|
|
28
|
-
|
|
29
|
-
Even schema documents follow this structure.
|
|
30
|
-
|
|
31
|
-
### Examples :
|
|
32
|
-
|
|
33
|
-
A system defined schema :
|
|
34
|
-
```
|
|
35
|
-
{
|
|
36
|
-
schema:"schema"
|
|
37
|
-
data : {
|
|
38
|
-
name: "system_tags",
|
|
39
|
-
.....
|
|
40
|
-
},
|
|
41
|
-
...
|
|
42
|
-
}
|
|
43
|
-
```
|
|
44
|
-
(In this example, the schema of this doc is `schema` because it stores the schema document, which will be use to validate documents that follows this schema)
|
|
3
|
+
[](https://github.com/shubhvjain/beanbagdb/tree/main)
|
|
45
4
|
|
|
46
|
-
|
|
47
|
-
```
|
|
48
|
-
{
|
|
49
|
-
schema:"system_tags",
|
|
50
|
-
data:{
|
|
51
|
-
tags:["tag1","tag2"]
|
|
52
|
-
}
|
|
53
|
-
....
|
|
54
|
-
}
|
|
55
|
-
```
|
|
56
|
-
User Defined schemas :
|
|
57
|
-
```
|
|
58
|
-
{
|
|
59
|
-
"schema":"schema",
|
|
60
|
-
"data":{
|
|
61
|
-
"name":"contacts",
|
|
62
|
-
...
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
```
|
|
66
|
-
And a sample document based on this user defined schema might look like :
|
|
67
|
-
```
|
|
68
|
-
{
|
|
69
|
-
schema:"contacts",
|
|
70
|
-
"data":{
|
|
71
|
-
"name":"Human 1",
|
|
72
|
-
"email":"human@on.earth"
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
```
|
|
5
|
+
[](https://www.npmjs.com/package/beanbagdb)
|
|
76
6
|
|
|
77
|
-
|
|
78
|
-
To ensure the system functions smoothly, each DB is initialized with a set of system defined schemas and seed documents. These are automatically added when the database is first created. These system defined are typically named with the prefix `system_`.
|
|
7
|
+
[](http://svja.in/beanbagdb/)
|
|
79
8
|
|
|
80
|
-
|
|
81
|
-
- `logs` : to log system and user actions
|
|
82
|
-
- `settings` : System level settings (`name`,`value`,`json` for more details)
|
|
83
|
-
- `keys` : user level settings , these are encrypted and stored in the DB
|
|
84
|
-
- `secrets` : encrypted text (TODO)
|
|
85
|
-
- `relations` : To create a network of relations (TODO)
|
|
86
|
-
- `index` : (TODO)
|
|
87
|
-
- `scripts` : (TODO)
|
|
88
|
-
|
|
89
|
-
## The BeanBagDB class
|
|
90
|
-
|
|
91
|
-
The `BeanBagDB` class contains the the logical part of how to interact with a local database. However, it does not itself makes any changes in the database. To make it (somewhat) compatible with multiple databases (e.g. CouchDB on the server, PouchDB in the browser), the class takes an db_instance object where the actual CRUD actions on the database can be performed.
|
|
92
|
-
|
|
93
|
-
To add support for a database, we extend the `BeanBagDB` class.
|
|
94
|
-
|
|
95
|
-
### API
|
|
96
|
-
- `initialize_db()`
|
|
97
|
-
- `log(stuff={whatever})`
|
|
98
|
-
- `get_setting_doc(setting_name)`
|
|
99
|
-
- `get_schema_doc()`
|
|
100
|
-
- `validate_data()`
|
|
101
|
-
- `insert_pre_check()`
|
|
102
|
-
- `insert()`
|
|
103
|
-
- `get()`
|
|
104
|
-
- `load_doc()`
|
|
105
|
-
- `update_data()`
|
|
106
|
-
- ...
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
## JSON Schema (in progress)
|
|
110
|
-
[Source](https://json-schema.org/) and [another](https://www.learnjsonschema.com/2020-12/)
|
|
111
|
-
|
|
112
|
-
### Basic schema structure
|
|
113
|
-
```
|
|
114
|
-
{
|
|
115
|
-
"name":"",
|
|
116
|
-
"description":"",
|
|
117
|
-
"properties":{
|
|
118
|
-
|
|
119
|
-
},
|
|
120
|
-
"settings":{
|
|
9
|
+
<div style="text-align:center">
|
|
121
10
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
```
|
|
125
|
-
#### Properties:
|
|
126
|
-
- Settings :
|
|
127
|
-
- `additionalProperties:true`
|
|
128
|
-
- `required:[]`
|
|
129
|
-
-
|
|
130
|
-
- Defining custom fields :
|
|
131
|
-
- `type:""` Valid values: ``
|
|
11
|
+
<img src="./doc-src/logo.png" alt="Alt text" style="width:auto; height:100px">
|
|
12
|
+
</div>
|
|
132
13
|
|
|
133
14
|
|
|
134
|
-
|
|
135
|
-
- `primary_key:[]`
|
|
136
|
-
- `editable_fields:[]`
|
|
137
|
-
- `single_record : true`
|
|
15
|
+
Please see the project [documentation website](http://svja.in/beanbagdb/) for more details.
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
## The Database architecture
|
|
2
|
+
A BeanbagDB is a collection of JSON documents. In a NoSQL database, documents don't need to follow a specific schema. Typically, the developer defines a schema based on the specific problem the app is intended to solve.
|
|
3
|
+
|
|
4
|
+
While, BeanBagDB allows users to create their own schemas for documents, all document internally share a consistent structure that accommodates the user defined schema.
|
|
5
|
+
|
|
6
|
+
Each document in the database follows this structure :
|
|
7
|
+
```
|
|
8
|
+
{
|
|
9
|
+
_id, _rev
|
|
10
|
+
data : {
|
|
11
|
+
user data
|
|
12
|
+
},
|
|
13
|
+
schema: "name_of_the_schema",
|
|
14
|
+
meta : {},
|
|
15
|
+
}
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Here, the `data` object contains user's information, while the `schema` defines it's associated structure. The `meta` field holds metadata such as creation and last updated on date and user defined tags.
|
|
19
|
+
|
|
20
|
+
Even schema documents follow this structure.
|
|
21
|
+
|
|
22
|
+
### Examples :
|
|
23
|
+
|
|
24
|
+
A system defined schema :
|
|
25
|
+
```
|
|
26
|
+
{
|
|
27
|
+
schema:"schema"
|
|
28
|
+
data : {
|
|
29
|
+
name: "system_tags",
|
|
30
|
+
.....
|
|
31
|
+
},
|
|
32
|
+
...
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
(In this example, the schema of this doc is `schema` because it stores the schema document, which will be use to validate documents that follows this schema)
|
|
36
|
+
|
|
37
|
+
The document adhering to this schema might look like :
|
|
38
|
+
```
|
|
39
|
+
{
|
|
40
|
+
schema:"system_tags",
|
|
41
|
+
data:{
|
|
42
|
+
tags:["tag1","tag2"]
|
|
43
|
+
}
|
|
44
|
+
....
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
User Defined schemas :
|
|
48
|
+
```
|
|
49
|
+
{
|
|
50
|
+
"schema":"schema",
|
|
51
|
+
"data":{
|
|
52
|
+
"name":"contacts",
|
|
53
|
+
...
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
And a sample document based on this user defined schema might look like :
|
|
58
|
+
```
|
|
59
|
+
{
|
|
60
|
+
schema:"contacts",
|
|
61
|
+
"data":{
|
|
62
|
+
"name":"Human 1",
|
|
63
|
+
"email":"human@on.earth"
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### System defined schemas
|
|
69
|
+
To ensure the system functions smoothly, each DB is initialized with a set of system defined schemas and seed documents. These are automatically added when the database is first created. These system defined are typically named with the prefix `system_`.
|
|
70
|
+
|
|
71
|
+
List of system schemas :
|
|
72
|
+
- `logs` : to log system and user actions
|
|
73
|
+
- `settings` : System level settings (`name`,`value`,`json` for more details)
|
|
74
|
+
- `keys` : user level settings , these are encrypted and stored in the DB
|
|
75
|
+
- `secrets` : encrypted text (TODO)
|
|
76
|
+
- `relations` : To create a network of relations (TODO)
|
|
77
|
+
- `index` : (TODO)
|
|
78
|
+
- `scripts` : (TODO)
|
|
79
|
+
|
|
80
|
+
## The BeanBagDB class
|
|
81
|
+
|
|
82
|
+
The `BeanBagDB` class contains the the logical part of how to interact with a local database. However, it does not itself makes any changes in the database. To make it (somewhat) compatible with multiple databases (e.g. CouchDB on the server, PouchDB in the browser), the class takes an db_instance object where the actual CRUD actions on the database can be performed.
|
|
83
|
+
|
|
84
|
+
To add support for a database, we extend the `BeanBagDB` class.
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
## JSON Schema (in progress)
|
|
88
|
+
[Source](https://json-schema.org/) and [another](https://www.learnjsonschema.com/2020-12/)
|
|
89
|
+
|
|
90
|
+
### Basic schema structure
|
|
91
|
+
```
|
|
92
|
+
{
|
|
93
|
+
"name":"",
|
|
94
|
+
"description":"",
|
|
95
|
+
"properties":{
|
|
96
|
+
|
|
97
|
+
},
|
|
98
|
+
"settings":{
|
|
99
|
+
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
#### Properties:
|
|
104
|
+
- Settings :
|
|
105
|
+
- `additionalProperties:true`
|
|
106
|
+
- `required:[]`
|
|
107
|
+
-
|
|
108
|
+
- Defining custom fields :
|
|
109
|
+
- `type:""` Valid values: ``
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
#### Settings :
|
|
113
|
+
- `primary_key:[]`
|
|
114
|
+
- `editable_fields:[]`
|
|
115
|
+
- `single_record : true`
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Getting started
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# How to add a new schema
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# How to use plugins
|
package/jsdoc.json
CHANGED
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "beanbagdb",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.52",
|
|
4
4
|
"description": "A JS library to introduce a schema layer to a No-SQL local database",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"module": "src/index.js",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"scripts": {
|
|
9
|
-
"test": "mocha"
|
|
9
|
+
"test": "mocha",
|
|
10
|
+
"docgen": "npx jsdoc -c jsdoc.json"
|
|
10
11
|
},
|
|
11
12
|
"repository": {
|
|
12
13
|
"type": "git",
|