beanbagdb 0.8.6 → 0.8.8

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.
@@ -1,15 +1,12 @@
1
1
  {
2
- "0_about": {
3
- "title": "About BeanBagDB"
4
- },
5
- "1_getting-started": {
2
+ "getting-started": {
6
3
  "title": "Getting Started"
7
4
  },
8
- "2_schema": {
5
+ "schema": {
9
6
  "title": "How to create a schema?"
10
7
  },
11
8
 
12
- "3_plugins": {
9
+ "plugins": {
13
10
  "title": "How to use plugins?"
14
11
  }
15
12
  }
@@ -0,0 +1,218 @@
1
+ /* Docdash Dark Theme - Semantic Color System */
2
+ * { box-sizing: border-box; }
3
+
4
+ :root {
5
+ /* Core */
6
+ --color-bg-primary: #0f1117;
7
+ --color-bg-secondary: #171e2d;
8
+ --color-bg-card: #1a1f2a;
9
+ --color-text-primary: #e2e8f0;
10
+ --color-text-secondary: #a1a8c0;
11
+
12
+ /* Accents */
13
+ --color-primary: #3b82f6;
14
+ --color-primary-hover: #2563eb;
15
+ --color-accent: #a855f7;
16
+ --color-accent-hover: #9333ea;
17
+
18
+ /* Neutrals */
19
+ --color-border: #334155;
20
+ --color-border-light: #475569;
21
+ --color-surface: #1e293b;
22
+
23
+ /* UI */
24
+ --color-code-bg: #0f172a;
25
+ --color-code-fg: #f1f5f9;
26
+ --color-nav-bg: #111827;
27
+ --color-nav-fg: #d1d5db;
28
+ --color-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
29
+ }
30
+
31
+ html, body {
32
+ height: 100%;
33
+ width: 100%;
34
+ background-color: var(--color-bg-primary) !important;
35
+ color: var(--color-text-primary) !important;
36
+ }
37
+
38
+ body {
39
+ margin: 0 auto;
40
+ padding: 0 20px;
41
+ font-family: 'Helvetica Neue', Helvetica, sans-serif;
42
+ font-size: 16px;
43
+ }
44
+
45
+ img { max-width: 100%; }
46
+
47
+ a, a:active {
48
+ color: var(--color-primary) !important;
49
+ text-decoration: none;
50
+ }
51
+
52
+ a:hover {
53
+ color: var(--color-primary-hover) !important;
54
+ }
55
+
56
+ article a {
57
+ border-bottom: 1px solid var(--color-border-light) !important;
58
+ }
59
+
60
+ article a:hover, article a:active {
61
+ border-bottom-color: var(--color-primary) !important;
62
+ }
63
+
64
+ h1, h2, h3, h4, h5, h6 {
65
+ color: var(--color-text-primary) !important;
66
+ font-weight: 400;
67
+ margin: 0;
68
+ }
69
+
70
+ h1 {
71
+ font-weight: 300;
72
+ font-size: 48px;
73
+ margin: 1em 0 0.5em;
74
+ }
75
+
76
+ h1.page-title {
77
+ font-size: 48px;
78
+ margin: 1em 30px;
79
+ line-height: 100%;
80
+ word-wrap: break-word;
81
+ }
82
+
83
+ h2 { font-size: 24px; margin: 1.5em 0 0.3em; }
84
+ h3 { font-size: 24px; margin: 1.2em 0 0.3em; }
85
+ h4 { font-size: 18px; margin: 1em 0 0.2em; color: var(--color-text-secondary) !important; }
86
+
87
+ h4.name {
88
+ color: #fff !important;
89
+ background: var(--color-primary) !important;
90
+ box-shadow: var(--color-shadow) !important;
91
+ border-top: 1px solid var(--color-border-light) !important;
92
+ border-bottom: 1px solid var(--color-border-light) !important;
93
+ margin: 1.5em 0 0.5em;
94
+ padding: 0.75em 0 0.75em 10px;
95
+ }
96
+
97
+ h4.name a { color: #fff !important; }
98
+ h4.name a:hover { border-bottom-color: var(--color-accent-hover) !important; }
99
+
100
+ .usertext h1 { font-size: 24px; margin: 2.5em 0 1em; }
101
+ .usertext h2 { font-size: 18px; margin: 2em 0 0.5em; }
102
+ .usertext h3 { font-size: 15px; margin: 1.5em 0 0; }
103
+ .usertext h5, .usertext h6 { color: var(--color-text-secondary) !important; }
104
+
105
+ tt, code, kbd, samp, pre {
106
+ font-family: Consolas, Monaco, 'Andale Mono', monospace;
107
+ background: var(--color-code-bg) !important;
108
+ color: var(--color-code-fg) !important;
109
+ }
110
+
111
+ tt, code, kbd, samp { padding: 1px 5px; }
112
+ pre { padding-bottom: 1em; }
113
+
114
+ #main { float: right; width: calc(100% - 240px); }
115
+
116
+ section {
117
+ background-color: var(--color-bg-card) !important;
118
+ padding: 0 0 0 30px;
119
+ }
120
+
121
+ nav {
122
+ float: left;
123
+ display: block;
124
+ width: 250px;
125
+ background: var(--color-nav-bg) !important;
126
+ overflow: auto;
127
+ position: fixed;
128
+ height: 100%;
129
+ }
130
+
131
+ nav h3 {
132
+ color: var(--color-text-primary) !important;
133
+ }
134
+
135
+ nav ul a, nav ul a:active {
136
+ color: var(--color-nav-fg) !important;
137
+ }
138
+
139
+ nav a:hover, nav a:active {
140
+ color: var(--color-primary) !important;
141
+ }
142
+
143
+ nav ul ul a {
144
+ color: var(--color-text-secondary) !important;
145
+ border-left: 1px solid var(--color-border) !important;
146
+ }
147
+
148
+ nav ul ul a, nav ul ul a:active { padding-left: 20px; }
149
+
150
+ footer {
151
+ color: var(--color-text-secondary) !important;
152
+ margin-left: 250px;
153
+ padding: 15px;
154
+ font-style: italic;
155
+ font-size: 90%;
156
+ }
157
+
158
+ .signature {
159
+ color: var(--color-text-primary) !important;
160
+ }
161
+
162
+ .prettyprint.source, .prettyprint code {
163
+ background-color: var(--color-code-bg) !important;
164
+ color: var(--color-code-fg) !important;
165
+ }
166
+
167
+ .prettyprint.linenums li {
168
+ border-left: 3px solid var(--color-primary) !important;
169
+ }
170
+
171
+ .prettyprint.linenums li.selected, .prettyprint.linenums li.selected * {
172
+ background-color: rgba(59, 130, 246, 0.2) !important;
173
+ }
174
+
175
+ table {
176
+ border: 1px solid var(--color-border) !important;
177
+ box-shadow: var(--color-shadow) !important;
178
+ background-color: var(--color-bg-card) !important;
179
+ border-collapse: collapse;
180
+ }
181
+
182
+ thead tr {
183
+ background-color: var(--color-surface) !important;
184
+ border-bottom: 1px solid var(--color-border) !important;
185
+ }
186
+
187
+ td, th {
188
+ border-top: 1px solid var(--color-border-light) !important;
189
+ color: var(--color-text-primary) !important;
190
+ }
191
+
192
+ .params td {
193
+ border-top-color: rgba(51, 65, 85, 0.5) !important;
194
+ }
195
+
196
+ .navicon, .navicon:before, .navicon:after {
197
+ background: var(--color-text-primary) !important;
198
+ }
199
+
200
+ .nav-trigger:checked + label.plus .navicon:before,
201
+ .nav-trigger:checked + label.x .navicon:before,
202
+ .nav-trigger:checked + label.plus .navicon:after,
203
+ .nav-trigger:checked + label.x .navicon:after {
204
+ background: #fff !important;
205
+ }
206
+
207
+ .overlay {
208
+ background: rgba(0,0,0,0.5) !important;
209
+ }
210
+
211
+ /* Responsive */
212
+ @media only screen and (max-width: 680px) {
213
+ nav {
214
+ left: -250px;
215
+ transition: left 0.2s;
216
+ }
217
+ footer { margin-left: 0; }
218
+ }
@@ -1,6 +1,3 @@
1
- # Getting started
2
-
3
-
4
1
 
5
2
  ### Nodes and edges
6
3
 
@@ -1,4 +1,4 @@
1
- # How to use plugins
1
+ to use a plugin:
2
2
 
3
3
  ```
4
4
  // MyPlugin.js
@@ -0,0 +1 @@
1
+ Adding a new schema
package/index.md CHANGED
@@ -1 +1,115 @@
1
- This is where i write the documentation
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`
package/jsdoc.json CHANGED
@@ -8,14 +8,26 @@
8
8
  "destination": "./docs-static",
9
9
  "recurse": true,
10
10
  "readme":"./index.md",
11
- "tutorials": "./doc-src"
11
+ "tutorials": "./doc-src",
12
+ "template": "node_modules/docdash"
12
13
  },
13
14
  "plugins": [
14
15
  "plugins/markdown"
15
16
  ],
16
17
  "templates": {
17
18
  "default": {
18
- "outputSourceFiles": false
19
+ "outputSourceFiles": false,
20
+ "staticFiles": {
21
+ "include": ["./doc-src/custom-dark.css"]
22
+ }
19
23
  }
24
+ },
25
+ "markdown": {
26
+ "idInHeadings": true
27
+ },
28
+ "docdash":{
29
+ "sort":false,
30
+ "search":false,
31
+ "scripts":["custom-dark.css"]
20
32
  }
21
33
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "beanbagdb",
3
- "version": "0.8.6",
3
+ "version": "0.8.8",
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",
@@ -30,6 +30,7 @@
30
30
  "ajv": "^8.17.1",
31
31
  "chai": "^5.1.1",
32
32
  "chai-as-promised": "^8.0.0",
33
+ "docdash": "^2.0.2",
33
34
  "dotenv": "^16.4.5",
34
35
  "jsdoc": "^4.0.3",
35
36
  "mocha": "^10.7.3",
package/src/index.js CHANGED
@@ -836,6 +836,20 @@ export class BeanBagDB {
836
836
  editable_meta_schema: async (criteria)=>{
837
837
  let e = sys_sch.editable_metadata_schema
838
838
  return e
839
+ },
840
+ related_doc: async (criteria) =>{
841
+ // criteria can be link or id
842
+ let get_doc = await this.read(criteria)
843
+ if(get_doc.doc){
844
+ let node = get_doc.doc._id
845
+ let data = await this.search({selector:{
846
+ "schema":"system_edge",
847
+ "$or":[ {'data.node1':{"$in":node}},{'data.node2':{"$in":node}}]
848
+ },fields:["_id","meta","schema"]})
849
+ return data
850
+ }else{
851
+ throw new ValidationError("Doc not found")
852
+ }
839
853
  }
840
854
  }
841
855
  if(!input.type){throw new ValidationError("No type provided. Must be: "+Object.keys(fetch_docs).join(","))}
@@ -1,115 +0,0 @@
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`
@@ -1 +0,0 @@
1
- # How to add a new schema