beanbagdb 0.5.75 → 0.5.77

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "beanbagdb",
3
- "version": "0.5.75",
3
+ "version": "0.5.77",
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",
package/src/index.js CHANGED
@@ -268,21 +268,19 @@ export class BeanBagDB {
268
268
 
269
269
  let app_doc = { ... app_data.meta, version: latest_version}
270
270
  try {
271
- await this.save_setting_doc(app_data.meta.name, {
272
- value: app_doc,
273
- });
274
- } catch (error) {
275
- console.log(error)
276
- console.log("error in storing/updating beanbagdb_version")
277
- }
278
-
279
- try {
271
+ // modify the app setting doc
272
+ await this.modify_setting(app_data.meta.name,app_doc,"update")
273
+
274
+ // add a new log
280
275
  let new_log_doc = this._get_blank_doc("system_log")
281
276
  new_log_doc.data = {text,data:{steps},time:this.util_get_now_unix_timestamp(),app:app_data.meta.name}
282
277
  await this.db_api.insert(new_log_doc);
283
278
  console.log("init logged")
279
+
284
280
  } catch (error) {
285
281
  console.log(error)
282
+ console.log("error in storing/updating beanbagdb_version")
283
+ throw error
286
284
  }
287
285
  return app_doc
288
286
  }
@@ -547,9 +545,9 @@ export class BeanBagDB {
547
545
  // doc already exists,
548
546
  let doc = { ...doc_search.docs[0] };
549
547
  if (Array.isArray(value)) {
550
- doc.data.value = update_mode === "append" ? [...value, new_data] : new_data; // "update" mode replaces the value
548
+ doc.data.value = update_mode === "append" ? [...doc.data.value, value] : value; // "update" mode replaces the value
551
549
  } else {
552
- doc.data.value = update_mode === "append" ? { ...value, ...new_data } : new_data; // "update" mode replaces the value
550
+ doc.data.value = update_mode === "append" ? { ...doc.data.value, ...value } : value; // "update" mode replaces the value
553
551
  }
554
552
  // finally update it
555
553
  doc["meta"]["updated_on"] = this.util_get_now_unix_timestamp();
@@ -559,9 +557,11 @@ export class BeanBagDB {
559
557
 
560
558
  } else {
561
559
  // doc does not exists, generate a new one
562
- let new_doc = {value, name};
563
- let d = await this.create("system_setting",new_doc)
564
- return d;
560
+ let new_log_doc = this._get_blank_doc("system_setting")
561
+ new_log_doc.data = {value, name}
562
+ await this.db_api.insert(new_log_doc);
563
+
564
+
565
565
  }
566
566
  }
567
567
 
@@ -709,7 +709,7 @@ export class BeanBagDB {
709
709
  * @param {object} node2
710
710
  * @param {string} edge_name
711
711
  * @param {*} edge_label
712
- * @returns
712
+ * @returns {Object}
713
713
  */
714
714
  async create_edge(node1,node2,edge_name,edge_label=""){
715
715
  this._check_ready_to_use();
@@ -1248,10 +1248,21 @@ async _upgrade_schema_in_bulk(schemas,log_upgrade=false,log_message="Schema Upgr
1248
1248
  * "banana-earth-rain".
1249
1249
  *
1250
1250
  */
1251
- util_generate_random_link() {
1252
- // prettier-ignore
1253
- const dictionary = ['rain', 'mars', 'banana', 'earth', 'kiwi', 'mercury', 'fuji', 'hurricane', 'matterhorn', 'snow', 'saturn', 'jupiter', 'peach', 'wind', 'pluto', 'apple', 'k2', 'storm', 'venus', 'denali', 'cloud', 'sunshine', 'mango', 'drizzle', 'pineapple', 'aconcagua', 'gasherbrum', 'apricot', 'neptune', 'fog', 'orange', 'blueberry', 'kilimanjaro', 'uranus', 'grape', 'storm', 'montblanc', 'lemon', 'chooyu', 'raspberry', 'cherry', 'thunder', 'vinson', 'breeze', 'elbrus', 'everest', 'parbat', 'makalu', 'nanga', 'kangchenjunga', 'lightning', 'cyclone', 'comet', 'asteroid', 'pomegranate', 'nectarine', 'clementine', 'strawberry', 'tornado', 'avalanche', 'andes', 'rockies', 'himalayas', 'pyrenees', 'carpathians', 'cascade', 'etna', 'vesuvius', 'volcano', 'tundra', 'whirlwind', 'iceberg', 'eclipse', 'zephyr', 'tropic', 'monsoon', 'aurora'];
1254
- return Array.from({ length: 3 },() => dictionary[Math.floor(Math.random() * dictionary.length)]).join("-");
1251
+ util_generate_random_link(type=1) {
1252
+ const options = {
1253
+ 0:()=>{
1254
+ // prettier-ignore
1255
+ const dictionary = ['rain', 'mars', 'banana', 'earth', 'kiwi', 'mercury', 'fuji', 'hurricane', 'matterhorn', 'snow', 'saturn', 'jupiter', 'peach', 'wind', 'pluto', 'apple', 'k2', 'storm', 'venus', 'denali', 'cloud', 'sunshine', 'mango', 'drizzle', 'pineapple', 'aconcagua', 'gasherbrum', 'apricot', 'neptune', 'fog', 'orange', 'blueberry', 'kilimanjaro', 'uranus', 'grape', 'storm', 'montblanc', 'lemon', 'chooyu', 'raspberry', 'cherry', 'thunder', 'vinson', 'breeze', 'elbrus', 'everest', 'parbat', 'makalu', 'nanga', 'kangchenjunga', 'lightning', 'cyclone', 'comet', 'asteroid', 'pomegranate', 'nectarine', 'clementine', 'strawberry', 'tornado', 'avalanche', 'andes', 'rockies', 'himalayas', 'pyrenees', 'carpathians', 'cascade', 'etna', 'vesuvius', 'volcano', 'tundra', 'whirlwind', 'iceberg', 'eclipse', 'zephyr', 'tropic', 'monsoon', 'aurora'];
1256
+ return Array.from({ length: 3 },() => dictionary[Math.floor(Math.random() * dictionary.length)]).join("-");
1257
+ },
1258
+ 1:()=>{
1259
+ const length = Math.floor(Math.random() * 3) + 6; // Random length: 6, 7, or 8
1260
+ const hexNumber = Math.floor(Math.random() * Math.pow(16, length)).toString(16);
1261
+ return hexNumber.padStart(length, '0'); // Ensure it has the desired length
1262
+
1263
+ }
1264
+ }
1265
+ return options[type]()
1255
1266
  }
1256
1267
  }
1257
1268
 
@@ -8,7 +8,8 @@ export const default_app = {
8
8
  name: "schema",
9
9
  description:"Meta-schema or the schema for defining other schemas",
10
10
  system_generated:true,
11
- version:0.80,
11
+ version:0.86,
12
+ title:"Schema document",
12
13
  schema: {
13
14
  type: "object",
14
15
  additionalProperties: false,
@@ -40,6 +41,13 @@ export const default_app = {
40
41
  maxLength:1000,
41
42
  description:"A small description of what data in this schema stores."
42
43
  },
44
+ title:{
45
+ type:"string",
46
+ title:"About",
47
+ minLength:0,
48
+ maxLength:1000,
49
+ description:"A title to display with records."
50
+ },
43
51
  schema: {
44
52
  type: "object",
45
53
  title:"JSON Schema specification",
@@ -98,20 +106,21 @@ export const default_app = {
98
106
  required :["primary_keys","non_editable_fields","encrypted_fields"]
99
107
  },
100
108
  },
101
- required: ["name","version","description","schema", "settings"],
109
+ required: ["name","description","schema", "settings","title"],
102
110
  },
103
111
  settings: {
104
112
  primary_keys: ["name"],
105
113
  non_editable_fields:[],
106
114
  encrypted_fields:[],
107
- display_fields:["name","version","description"]
115
+ display_fields:["name","version","description","title"]
108
116
  },
109
117
  },
110
118
  {
111
119
  system_generated:true,
112
- version:0.61,
120
+ version:0.62,
113
121
  description:"To store user defined key. this can include anything like API tokens etc. There is a special method to fetch this. The values are encrypted",
114
122
  name: "system_key",
123
+ title:"System key",
115
124
  schema: {
116
125
  type: "object",
117
126
  additionalProperties: true,
@@ -144,10 +153,11 @@ export const default_app = {
144
153
  },
145
154
  },
146
155
  {
147
- version:0.65,
156
+ version:0.66,
148
157
  system_generated:true,
149
158
  description:"The system relies on these settings for proper functioning or enabling optional features.",
150
159
  name: "system_setting",
160
+ title:"System Setting",
151
161
  schema: {
152
162
  required:["name","value"],
153
163
  type: "object",
@@ -172,8 +182,9 @@ export const default_app = {
172
182
  },
173
183
  {
174
184
  name:"system_edge_constraint",
185
+ title:"Edge constraint",
175
186
  system_generated:true,
176
- version:0.50,
187
+ version:0.51,
177
188
  description: "To define edge constraints for simple directed graph of records.",
178
189
  schema:{
179
190
  type: "object",
@@ -224,8 +235,9 @@ export const default_app = {
224
235
  },
225
236
  {
226
237
  name:"system_edge",
238
+ title:"Edge in the system graph",
227
239
  system_generated:true,
228
- version:0.50,
240
+ version:0.51,
229
241
  description: "To define edges in the simple directed graph of records.",
230
242
  schema:{
231
243
  type: "object",
@@ -251,8 +263,9 @@ export const default_app = {
251
263
  },
252
264
  {
253
265
  name:"system_media",
266
+ title:"Media content",
254
267
  system_generated:true,
255
- version:0.60,
268
+ version:0.61,
256
269
  description: "To store images as Base64",
257
270
  schema:{
258
271
  type: "object",
@@ -282,7 +295,8 @@ export const default_app = {
282
295
  {
283
296
  name:"system_log",
284
297
  system_generated:true,
285
- version:0.50,
298
+ title:"System log",
299
+ version:0.51,
286
300
  description: "To define edges in the simple directed graph of records.",
287
301
  schema:{
288
302
  type: "object",
@@ -180,6 +180,7 @@ describe("Edge insertion test", async () => {
180
180
  {
181
181
  name: "player",
182
182
  description:"Player",
183
+ title:"Player",
183
184
  schema: {
184
185
  additionalProperties:true,
185
186
  type:"object",
@@ -198,6 +199,7 @@ describe("Edge insertion test", async () => {
198
199
  {
199
200
  name: "team",
200
201
  description:"Team",
202
+ title:"Team",
201
203
  schema: {
202
204
  additionalProperties:true,
203
205
  type:"object",
@@ -216,6 +218,7 @@ describe("Edge insertion test", async () => {
216
218
  {
217
219
  name: "match",
218
220
  description:"Match",
221
+ title:"Match",
219
222
  schema: {
220
223
  type:"object",
221
224
  additionalProperties:true,
@@ -35,6 +35,7 @@ describe("Schema doc insertion gives errors when", async () => {
35
35
  {
36
36
  name: "",
37
37
  description: "",
38
+ title:"",
38
39
  schema: {},
39
40
  settings: {},
40
41
  },
@@ -45,6 +46,7 @@ describe("Schema doc insertion gives errors when", async () => {
45
46
  name: "nos",
46
47
  description: "",
47
48
  schema: {},
49
+ title:"",
48
50
  settings: {},
49
51
  },
50
52
  ],
@@ -54,6 +56,7 @@ describe("Schema doc insertion gives errors when", async () => {
54
56
  name: "contact",
55
57
  description: "",
56
58
  schema: {},
59
+ title:"",
57
60
  settings: {},
58
61
  },
59
62
  ],
@@ -62,6 +65,7 @@ describe("Schema doc insertion gives errors when", async () => {
62
65
  {
63
66
  name: "contact",
64
67
  description: "This can be left blank",
68
+ title:"something",
65
69
  settings: {},
66
70
  },
67
71
  ],
@@ -370,6 +374,28 @@ describe("Schema doc insertion gives errors when", async () => {
370
374
  },
371
375
  },
372
376
  ],
377
+ [
378
+ "title missing",
379
+ {
380
+ name: "contact",
381
+ description: "This can be left blank",
382
+ schema: {
383
+ type: "object",
384
+ properties: {
385
+ name: { type: "string" },
386
+ address: { type: "object" },
387
+ secret: { type: "string" },
388
+ },
389
+ additionalProperties: true,
390
+ },
391
+ settings: {
392
+ primary_keys: ["name"],
393
+ non_editable_fields: ["mobile"],
394
+ single_record: false,
395
+ encrypted_fields: ["name"],
396
+ },
397
+ },
398
+ ],
373
399
  ];
374
400
 
375
401
  before(async () => {
@@ -538,6 +564,7 @@ describe("Doc insertion tests", async () => {
538
564
  const test_schema = {
539
565
  name:"book",
540
566
  description:"Test schema 1",
567
+ title:"Book",
541
568
  schema: {
542
569
  $schema: "http://json-schema.org/draft-07/schema#",
543
570
  type: "object",
@@ -733,6 +760,7 @@ describe("Doc insertion tests", async () => {
733
760
  describe("Doc insertion tests with encryption", async () => {
734
761
  const test_schema = {
735
762
  name:"book",
763
+ title:"Book",
736
764
  description:"Test schema 1",
737
765
  schema: {
738
766
  $schema: "http://json-schema.org/draft-07/schema#",
@@ -930,6 +958,7 @@ describe("Doc read tests", async () => {
930
958
  const test_schema = {
931
959
  name:"book",
932
960
  description:"Test schema 1",
961
+ title:"Book",
933
962
  schema: {
934
963
  $schema: "http://json-schema.org/draft-07/schema#",
935
964
  type: "object",
@@ -1119,6 +1148,7 @@ describe("Doc update tests", async () => {
1119
1148
  const test_schema = {
1120
1149
  name:"book",
1121
1150
  description:"Test schema 1",
1151
+ title:"Book",
1122
1152
  schema: {
1123
1153
  $schema: "http://json-schema.org/draft-07/schema#",
1124
1154
  type: "object",
@@ -1362,6 +1392,7 @@ describe("Doc delete tests", async () => {
1362
1392
  const test_schema = {
1363
1393
  name:"book",
1364
1394
  description:"Test schema 1",
1395
+ title:"Book",
1365
1396
  schema: {
1366
1397
  $schema: "http://json-schema.org/draft-07/schema#",
1367
1398
  type: "object",
@@ -1528,6 +1559,7 @@ describe("Doc search tests", async () => {
1528
1559
 
1529
1560
  const test_schema = {
1530
1561
  name:"book",
1562
+ title:"Book",
1531
1563
  description:"Test schema 1",
1532
1564
  schema: {
1533
1565
  $schema: "http://json-schema.org/draft-07/schema#",