beanbagdb 0.6.0 → 0.6.2
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 +8 -6
- package/src/system_schema.js +52 -0
- package/test/operations.test.js +2 -2
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -257,7 +257,7 @@ export class BeanBagDB {
|
|
|
257
257
|
|
|
258
258
|
// check if app setting record exists
|
|
259
259
|
let version_search = await this.db_api.search({
|
|
260
|
-
selector: { schema: "system_setting", "data.name": app_data.
|
|
260
|
+
selector: { schema: "system_setting", "data.name": app_data.app_id },
|
|
261
261
|
})
|
|
262
262
|
|
|
263
263
|
let update_required = true
|
|
@@ -275,7 +275,7 @@ export class BeanBagDB {
|
|
|
275
275
|
// if version is latest no additional steps required
|
|
276
276
|
// version mismatch => update all docs
|
|
277
277
|
|
|
278
|
-
let text = `Initializing ${app_data.
|
|
278
|
+
let text = `Initializing ${app_data.app_id} app to v.${latest_version}`
|
|
279
279
|
let steps = ["update started"]
|
|
280
280
|
|
|
281
281
|
for (let index = 0; index < app_data.schemas.length; index++) {
|
|
@@ -301,7 +301,7 @@ export class BeanBagDB {
|
|
|
301
301
|
// console.log(error);
|
|
302
302
|
if (error instanceof DocNotFoundError) {
|
|
303
303
|
// inserting new schema doc
|
|
304
|
-
if(schema_name=="schema"&& app_data.
|
|
304
|
+
if(schema_name=="schema"&& app_data.app_id=="beanbagdb_system"){
|
|
305
305
|
// this is to initialize the system schema
|
|
306
306
|
let schema_schema_doc = this._get_blank_doc("schema");
|
|
307
307
|
schema_schema_doc.data = schema_data;
|
|
@@ -346,7 +346,7 @@ export class BeanBagDB {
|
|
|
346
346
|
|
|
347
347
|
// add a new log
|
|
348
348
|
let new_log_doc = this._get_blank_doc("system_log")
|
|
349
|
-
new_log_doc.data = {text,data:{steps},time:this.util_get_now_unix_timestamp(),app:app_data.
|
|
349
|
+
new_log_doc.data = {text,data:{steps},time:this.util_get_now_unix_timestamp(),app:app_data.app_id}
|
|
350
350
|
await this.db_api.insert(new_log_doc);
|
|
351
351
|
console.log("init logged")
|
|
352
352
|
|
|
@@ -1043,13 +1043,16 @@ async _upgrade_schema_in_bulk(schemas,log_upgrade=false,log_message="Schema Upgr
|
|
|
1043
1043
|
if (!schema_name) {
|
|
1044
1044
|
throw new Error("Schema name not provided for the blank doc");
|
|
1045
1045
|
}
|
|
1046
|
+
let dt = this.util_get_now_unix_timestamp()
|
|
1047
|
+
let title = `${schema_name} document - ${dt}`
|
|
1046
1048
|
let doc = {
|
|
1047
1049
|
data: {},
|
|
1048
1050
|
meta: {
|
|
1049
|
-
created_on:
|
|
1051
|
+
created_on: dt,
|
|
1050
1052
|
tags: [],
|
|
1051
1053
|
app: {},
|
|
1052
1054
|
link: this.util_generate_random_link(), // there is a link by default. overwrite this if user provided one but only before checking if it is unique
|
|
1055
|
+
title: title
|
|
1053
1056
|
},
|
|
1054
1057
|
schema: schema_name,
|
|
1055
1058
|
};
|
|
@@ -1088,7 +1091,6 @@ async _upgrade_schema_in_bulk(schemas,log_upgrade=false,log_message="Schema Upgr
|
|
|
1088
1091
|
console.log(error)
|
|
1089
1092
|
throw new EncryptionError([{message:error.message}])
|
|
1090
1093
|
}
|
|
1091
|
-
|
|
1092
1094
|
}
|
|
1093
1095
|
|
|
1094
1096
|
/**
|
package/src/system_schema.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export const default_app = {
|
|
2
2
|
app_id: "beanbagdb_system",
|
|
3
3
|
meta: {
|
|
4
|
+
name: "beanbagdb_system",
|
|
4
5
|
description:
|
|
5
6
|
"This is the default system app required for proper functioning of the database",
|
|
6
7
|
},
|
|
@@ -363,6 +364,53 @@ export const default_app = {
|
|
|
363
364
|
encrypted_fields: [],
|
|
364
365
|
},
|
|
365
366
|
},
|
|
367
|
+
{
|
|
368
|
+
name: "system_script",
|
|
369
|
+
system_generated: true,
|
|
370
|
+
title: "Executable script",
|
|
371
|
+
active: true,
|
|
372
|
+
version: 0.1,
|
|
373
|
+
description: "To create scripts that implement some logic. Can run both on browser and client.",
|
|
374
|
+
schema: {
|
|
375
|
+
type: "object",
|
|
376
|
+
additionalProperties: true,
|
|
377
|
+
required: ["script","type","version"],
|
|
378
|
+
properties: {
|
|
379
|
+
type: {
|
|
380
|
+
type: "string",
|
|
381
|
+
default:"JS"
|
|
382
|
+
},
|
|
383
|
+
name: {
|
|
384
|
+
type: "string",
|
|
385
|
+
default:"script-name",
|
|
386
|
+
pattern: "^[a-zA-Z0-9\\-]+$"
|
|
387
|
+
},
|
|
388
|
+
script: {
|
|
389
|
+
type: "string",
|
|
390
|
+
description:"The script",
|
|
391
|
+
default:""
|
|
392
|
+
},
|
|
393
|
+
usage:{
|
|
394
|
+
type:"string",
|
|
395
|
+
description:"Documentation",
|
|
396
|
+
default:" "
|
|
397
|
+
},
|
|
398
|
+
version :{
|
|
399
|
+
type:"number",
|
|
400
|
+
default:0.1
|
|
401
|
+
},
|
|
402
|
+
log_execution:{
|
|
403
|
+
type:"boolean",
|
|
404
|
+
default:false
|
|
405
|
+
}
|
|
406
|
+
},
|
|
407
|
+
},
|
|
408
|
+
settings: {
|
|
409
|
+
primary_keys: ["name"],
|
|
410
|
+
non_editable_fields: [],
|
|
411
|
+
encrypted_fields: [],
|
|
412
|
+
},
|
|
413
|
+
},
|
|
366
414
|
],
|
|
367
415
|
records: [],
|
|
368
416
|
};
|
|
@@ -384,6 +432,10 @@ export const editable_metadata_schema = {
|
|
|
384
432
|
maxLength: 2000,
|
|
385
433
|
pattern: "^[a-zA-Z0-9-]+$",
|
|
386
434
|
},
|
|
435
|
+
title:{
|
|
436
|
+
type:"string",
|
|
437
|
+
maxLength:10000
|
|
438
|
+
}
|
|
387
439
|
},
|
|
388
440
|
};
|
|
389
441
|
|
package/test/operations.test.js
CHANGED
|
@@ -1371,7 +1371,7 @@ describe("Doc search tests", async () => {
|
|
|
1371
1371
|
it('all docs', async () => {
|
|
1372
1372
|
try {
|
|
1373
1373
|
let udata = await database3.search({selector:{}})
|
|
1374
|
-
assert(udata.docs.length==
|
|
1374
|
+
assert(udata.docs.length==13)
|
|
1375
1375
|
} catch (error) {
|
|
1376
1376
|
//console.log(error)
|
|
1377
1377
|
throw error
|
|
@@ -1391,7 +1391,7 @@ describe("Doc search tests", async () => {
|
|
|
1391
1391
|
it('read docs 2', async () => {
|
|
1392
1392
|
try {
|
|
1393
1393
|
let udata = await database3.search({selector:{"schema":"schema"}})
|
|
1394
|
-
assert(udata.docs.length==
|
|
1394
|
+
assert(udata.docs.length==9) // schema,book,setting,key,edge,edge_constraints
|
|
1395
1395
|
} catch (error) {
|
|
1396
1396
|
//console.log(error)
|
|
1397
1397
|
throw error
|