beanbagdb 0.5.45 → 0.5.46
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 +1 -1
- package/src/index.js +24 -2
- package/src/system_schema.js +9 -3
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -158,6 +158,10 @@ class BeanBagDB {
|
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
+
validate_schema_object(schema_doc){
|
|
162
|
+
|
|
163
|
+
}
|
|
164
|
+
|
|
161
165
|
/**
|
|
162
166
|
* Returns a document with the provided ID
|
|
163
167
|
* @param {String} doc_id - the doc Id (not the primary key)
|
|
@@ -370,6 +374,11 @@ class BeanBagDB {
|
|
|
370
374
|
|
|
371
375
|
//////// Helper method ////////
|
|
372
376
|
|
|
377
|
+
_generate_random_link(){
|
|
378
|
+
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'];
|
|
379
|
+
return Array.from({ length: 4 }, () => dictionary[Math.floor(Math.random() * dictionary.length)]).join('-');
|
|
380
|
+
}
|
|
381
|
+
|
|
373
382
|
_check_required_fields(requiredFields,obj){
|
|
374
383
|
for (const field of requiredFields) {
|
|
375
384
|
if (!obj[field]) {throw new Error(`${field} is required`);}
|
|
@@ -452,7 +461,8 @@ class BeanBagDB {
|
|
|
452
461
|
meta: {
|
|
453
462
|
createdOn: this._get_now_unix_timestamp(),
|
|
454
463
|
tags: [],
|
|
455
|
-
app :{}
|
|
464
|
+
app :{},
|
|
465
|
+
link : this._generate_random_link() // there is a link by default. overwrite this if user provided one but only before checking if it is unique
|
|
456
466
|
},
|
|
457
467
|
schema: schema_name,
|
|
458
468
|
};
|
|
@@ -527,7 +537,7 @@ class BeanBagDB {
|
|
|
527
537
|
* @param {Object} schema
|
|
528
538
|
* @param {Object} data
|
|
529
539
|
*/
|
|
530
|
-
async _insert_pre_checks(schema, data, settings = {}) {
|
|
540
|
+
async _insert_pre_checks(schema, data,meta={} ,settings = {}) {
|
|
531
541
|
// schema search
|
|
532
542
|
let sch_search = await this.search({
|
|
533
543
|
selector: { schema: "schema", "data.name": schema },
|
|
@@ -539,6 +549,18 @@ class BeanBagDB {
|
|
|
539
549
|
// validate data
|
|
540
550
|
this.validate_data(schemaDoc.schema, data);
|
|
541
551
|
|
|
552
|
+
// validate meta
|
|
553
|
+
this.validate_data(sys_sch.editable_metadata_schema, meta);
|
|
554
|
+
|
|
555
|
+
// duplicate meta.link check
|
|
556
|
+
if(meta.link){
|
|
557
|
+
let link_search = await this.search({ selector: {"meta.link":meta.link} });
|
|
558
|
+
console.log(link_search);
|
|
559
|
+
if (link_search.docs.length > 0) {
|
|
560
|
+
throw new Error("This link already exists in the database");
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
|
|
542
564
|
// special checks for special docs
|
|
543
565
|
// @TODO : for schema dos: settings fields must be in schema field
|
|
544
566
|
// @TODO : check if single record setting is set to true
|
package/src/system_schema.js
CHANGED
|
@@ -45,7 +45,7 @@ export const schema_schema = {
|
|
|
45
45
|
items: {
|
|
46
46
|
type: "string",
|
|
47
47
|
},
|
|
48
|
-
maxItems:
|
|
48
|
+
maxItems: 50,
|
|
49
49
|
},
|
|
50
50
|
encrypted_fields: {
|
|
51
51
|
type: "array",
|
|
@@ -53,7 +53,7 @@ export const schema_schema = {
|
|
|
53
53
|
items: {
|
|
54
54
|
type: "string",
|
|
55
55
|
},
|
|
56
|
-
maxItems:
|
|
56
|
+
maxItems: 50,
|
|
57
57
|
},
|
|
58
58
|
single_record: {
|
|
59
59
|
type: "boolean",
|
|
@@ -68,7 +68,7 @@ export const schema_schema = {
|
|
|
68
68
|
},
|
|
69
69
|
settings: {
|
|
70
70
|
primary_key: ["name"],
|
|
71
|
-
editable_fields: ["schema", "settings"],
|
|
71
|
+
editable_fields: ["schema", "settings","description"],
|
|
72
72
|
},
|
|
73
73
|
};
|
|
74
74
|
|
|
@@ -175,6 +175,12 @@ export const editable_metadata_schema = {
|
|
|
175
175
|
items:{type:"string"},
|
|
176
176
|
default:[],
|
|
177
177
|
maxItems: 40,
|
|
178
|
+
},
|
|
179
|
+
link:{
|
|
180
|
+
type:"string",
|
|
181
|
+
minLength:2,
|
|
182
|
+
maxLength:2000,
|
|
183
|
+
pattern: "^[a-zA-Z0-9-]+$"
|
|
178
184
|
}
|
|
179
185
|
}
|
|
180
186
|
}
|