beanbagdb 0.5.60 → 0.5.70
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 +123 -64
- package/src/system_schema.js +278 -236
- package/test/operations.test.js +2 -2
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -114,7 +114,7 @@ export class BeanBagDB {
|
|
|
114
114
|
*
|
|
115
115
|
* This method performs the following actions:
|
|
116
116
|
* - Pings the database.
|
|
117
|
-
* - Searches the database for the `
|
|
117
|
+
* - Searches the database for the `system_setting.beanbagdb_version` document.
|
|
118
118
|
* - Sets the class state as active if the version matches the current BeanBagDB version.
|
|
119
119
|
* - If the version does not match, calls `initialize()` to set up the database to the latest version.
|
|
120
120
|
* @todo Code to ping the DB and throw Connection error if failed to connect
|
|
@@ -123,17 +123,22 @@ export class BeanBagDB {
|
|
|
123
123
|
*/
|
|
124
124
|
async ready() {
|
|
125
125
|
// TODO Ping db
|
|
126
|
+
console.log("running ready....")
|
|
126
127
|
let version_search = await this.db_api.search({
|
|
127
|
-
selector: { schema: "
|
|
128
|
-
})
|
|
128
|
+
selector: { schema: "system_setting", "data.name": "beanbagdb_system" },
|
|
129
|
+
})
|
|
130
|
+
//console.log(version_search)
|
|
129
131
|
if (version_search.docs.length > 0) {
|
|
130
132
|
let doc = version_search.docs[0];
|
|
131
|
-
|
|
132
|
-
this.
|
|
133
|
+
//console.log(doc)
|
|
134
|
+
this.active = doc["data"]["value"]["version"] == this._version;
|
|
135
|
+
this.meta.beanbagdb_version_db = doc["data"]["value"]["version"];
|
|
133
136
|
}
|
|
134
137
|
if (this.active) {
|
|
135
138
|
console.log("Ready");
|
|
136
139
|
} else {
|
|
140
|
+
console.log("Not ready. Init required")
|
|
141
|
+
//throw new Error("Initialization required")
|
|
137
142
|
await this.initialize();
|
|
138
143
|
}
|
|
139
144
|
}
|
|
@@ -155,81 +160,132 @@ export class BeanBagDB {
|
|
|
155
160
|
*/
|
|
156
161
|
async initialize() {
|
|
157
162
|
// this works on its own but is usually called by ready automatically if required
|
|
158
|
-
|
|
159
163
|
// check for schema_scehma : if yes, check if latest and upgrade if required, if no create a new schema doc
|
|
160
|
-
let logs = ["init started"];
|
|
161
164
|
try {
|
|
162
|
-
let
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
full_doc["meta"]["updated_on"] = this.util_get_now_unix_timestamp();
|
|
168
|
-
await this.db_api.update(full_doc);
|
|
169
|
-
logs.push("new schema_schema v " + sys_sch.schema_schema.version);
|
|
170
|
-
}
|
|
165
|
+
let app_data = await this.initialize_app(sys_sch.default_app)
|
|
166
|
+
console.log(app_data)
|
|
167
|
+
this.meta.beanbagdb_version_db = this._version;
|
|
168
|
+
this.active = true;
|
|
169
|
+
return app_data
|
|
171
170
|
} catch (error) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
let schema_schema_doc = this._get_blank_doc("schema");
|
|
176
|
-
schema_schema_doc.data = sys_sch.schema_schema;
|
|
177
|
-
await this.db_api.insert(schema_schema_doc);
|
|
178
|
-
logs.push("init schema_schema v " + sys_sch.schema_schema.version);
|
|
179
|
-
}
|
|
171
|
+
console.log("Error in initializing instance")
|
|
172
|
+
console.log(error)
|
|
173
|
+
throw error
|
|
180
174
|
}
|
|
181
175
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
async initialize_app(app_data){
|
|
179
|
+
// app_data : meta(name,description), schemas[] , default_records:[]
|
|
180
|
+
// TODO check if add_data is valid
|
|
181
|
+
// calculate the app_version
|
|
182
|
+
let latest_version = 0
|
|
183
|
+
app_data.schemas.map(sch=>{latest_version = latest_version + sch.version})
|
|
184
|
+
app_data.records.map(sch=>{latest_version = latest_version + sch.version})
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
// check if app setting record exists
|
|
188
|
+
let version_search = await this.db_api.search({
|
|
189
|
+
selector: { schema: "system_setting", "data.name": app_data.meta.name },
|
|
190
|
+
})
|
|
191
|
+
|
|
192
|
+
let update_required = true
|
|
193
|
+
let doc
|
|
194
|
+
if (version_search.docs.length > 0) {
|
|
195
|
+
doc = version_search.docs[0];
|
|
196
|
+
if(doc["data"]["value"]["version"] == latest_version){
|
|
197
|
+
update_required = false
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// if no update required return the document
|
|
202
|
+
if(!update_required){return doc}
|
|
203
|
+
// if version is latest no additional steps required
|
|
204
|
+
// version mismatch => update all docs
|
|
205
|
+
|
|
206
|
+
let text = `Initializing ${app_data.meta.name} app to v.${latest_version}`
|
|
207
|
+
let steps = ["update started"]
|
|
208
|
+
|
|
209
|
+
for (let index = 0; index < app_data.schemas.length; index++) {
|
|
210
|
+
const schema_name = app_data.schemas[index]["name"];
|
|
211
|
+
const schema_data = app_data.schemas[index]
|
|
212
|
+
steps.push(`checking.${schema_name}`)
|
|
186
213
|
try {
|
|
187
214
|
// console.log(schema_name)
|
|
188
215
|
let schema1 = await this.get("schema",{name:schema_name})
|
|
189
216
|
if (schema1["data"]["version"] != schema_data.version) {
|
|
190
|
-
|
|
217
|
+
steps.push(`old.${schema_name}.v.${schema1["data"]["version"]}`);
|
|
191
218
|
let full_doc = await this.db_api.get(schema1["_id"]);
|
|
192
219
|
full_doc["data"] = { ...schema_data };
|
|
193
220
|
full_doc["meta"]["updated_on"] = this.util_get_now_unix_timestamp();
|
|
221
|
+
console.log(full_doc)
|
|
194
222
|
await this.db_api.update(full_doc);
|
|
195
|
-
|
|
223
|
+
|
|
224
|
+
steps.push(`new.${schema_name}.v=${schema_data.version}`);
|
|
225
|
+
}else{
|
|
226
|
+
steps.push(`${schema_name}.v.${schema1["data"]["version"]}=latest`)
|
|
196
227
|
}
|
|
197
228
|
} catch (error) {
|
|
198
229
|
// console.log(error);
|
|
199
230
|
if (error instanceof DocNotFoundError) {
|
|
200
231
|
// inserting new schema doc
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
schema_data
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
232
|
+
if(schema_name=="schema"&& app_data.meta.name=="beanbagdb_system"){
|
|
233
|
+
// this is to initialize the system schema
|
|
234
|
+
let schema_schema_doc = this._get_blank_doc("schema");
|
|
235
|
+
schema_schema_doc.data = schema_data;
|
|
236
|
+
//console.log(schema_schema_doc)
|
|
237
|
+
await this.db_api.insert(schema_schema_doc);
|
|
238
|
+
}else{
|
|
239
|
+
let system_schema = sys_sch.default_app.schemas[0]["schema"]
|
|
240
|
+
let new_schema_doc = this._get_blank_schema_doc(
|
|
241
|
+
"schema",
|
|
242
|
+
system_schema,
|
|
243
|
+
schema_data
|
|
244
|
+
);
|
|
245
|
+
await this.db_api.insert(new_schema_doc);
|
|
246
|
+
}
|
|
247
|
+
steps.push(`init.${schema_name}.v=${schema_data.version}`);
|
|
248
|
+
}else{
|
|
249
|
+
steps.push(`${schema_name}.error.message : ${error.message} `);
|
|
208
250
|
}
|
|
209
251
|
}
|
|
210
252
|
}
|
|
211
|
-
// store the logs in the log_doc , generate it for the first time
|
|
212
|
-
// console.log(logs)
|
|
213
|
-
if (logs.length > 1) {
|
|
214
|
-
// version needs to be updated in the object as well as settings and must be logged
|
|
215
|
-
logs.push("Init done");
|
|
216
|
-
|
|
217
|
-
await this.save_setting_doc("system_logs", {
|
|
218
|
-
value: { text: logs.join(","), added: this.util_get_now_unix_timestamp() },
|
|
219
|
-
on_update_array: "append",
|
|
220
|
-
});
|
|
221
|
-
await this.save_setting_doc("beanbagdb_version", {
|
|
222
|
-
value: this._version,
|
|
223
|
-
});
|
|
224
253
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
254
|
+
for (let index = 0; index < app_data.records.length; index++) {
|
|
255
|
+
const schema_name = app_data.records[index]["schema"]
|
|
256
|
+
const schema_data = app_data.records[index]["record"]
|
|
257
|
+
const record_title = app_data.records[index]["title"]
|
|
258
|
+
steps.push(`checking.records.${record_title}`)
|
|
259
|
+
try {
|
|
260
|
+
let new_doc = await this.create(schema_name,schema_data,app_data.records[index]["meta"])
|
|
261
|
+
steps.push(`doc.${record_title}.created`)
|
|
262
|
+
} catch (error) {
|
|
263
|
+
if(!(error instanceof DocCreationError)){
|
|
264
|
+
steps.push(`error in doc ${record_title} insertion: ${error.message}, doc: ${JSON.stringify(schema_data)}`)
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
let app_doc = { ... app_data.meta, version: latest_version}
|
|
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")
|
|
231
277
|
}
|
|
232
|
-
|
|
278
|
+
|
|
279
|
+
try {
|
|
280
|
+
let new_log_doc = this._get_blank_doc("system_log")
|
|
281
|
+
new_log_doc.data = {text,data:{steps},time:this.util_get_now_unix_timestamp(),app:app_data.meta.name}
|
|
282
|
+
await this.db_api.insert(new_log_doc);
|
|
283
|
+
console.log("init logged")
|
|
284
|
+
} catch (error) {
|
|
285
|
+
console.log(error)
|
|
286
|
+
}
|
|
287
|
+
return app_doc
|
|
288
|
+
}
|
|
233
289
|
|
|
234
290
|
|
|
235
291
|
/**
|
|
@@ -263,7 +319,7 @@ export class BeanBagDB {
|
|
|
263
319
|
}
|
|
264
320
|
|
|
265
321
|
let doc_search = await this.db_api.search({
|
|
266
|
-
selector: { schema: "
|
|
322
|
+
selector: { schema: "system_setting", "data.name": name },
|
|
267
323
|
});
|
|
268
324
|
if (doc_search.docs.length > 0) {
|
|
269
325
|
// doc already exists, check schema and update it : if it exists then it's value already exists and can be
|
|
@@ -293,7 +349,7 @@ export class BeanBagDB {
|
|
|
293
349
|
new_val.value = [new_data.value];
|
|
294
350
|
new_val.on_update_array = new_data.on_update_array;
|
|
295
351
|
}
|
|
296
|
-
let new_doc = this._get_blank_doc("
|
|
352
|
+
let new_doc = this._get_blank_doc("system_setting");
|
|
297
353
|
new_doc["data"] = {
|
|
298
354
|
name: name,
|
|
299
355
|
...new_val,
|
|
@@ -783,10 +839,10 @@ _check_nodes_edge(node1Rule, node2Rule, schema1, schema2) {
|
|
|
783
839
|
*/
|
|
784
840
|
_get_current_version() {
|
|
785
841
|
// current version is the sum of versions of all system defined schemas
|
|
786
|
-
let sum =
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
})
|
|
842
|
+
let sum = 0
|
|
843
|
+
// sys_sch.schema_schema.version;
|
|
844
|
+
sys_sch.default_app.schemas.map((item) => {sum = sum + item.version})
|
|
845
|
+
sys_sch.default_app.records.map((item) => {sum = sum + item.version})
|
|
790
846
|
if (sum == NaN) {
|
|
791
847
|
throw Error("Error in system schema version numbers");
|
|
792
848
|
}
|
|
@@ -916,7 +972,10 @@ _check_nodes_edge(node1Rule, node2Rule, schema1, schema2) {
|
|
|
916
972
|
this.util_validate_data(schemaDoc.schema, data);
|
|
917
973
|
|
|
918
974
|
// validate meta
|
|
919
|
-
|
|
975
|
+
if(Object.keys.length>0){
|
|
976
|
+
this.util_validate_data(sys_sch.editable_metadata_schema, meta)
|
|
977
|
+
}
|
|
978
|
+
|
|
920
979
|
|
|
921
980
|
// duplicate meta.link check
|
|
922
981
|
if (meta.link) {
|
package/src/system_schema.js
CHANGED
|
@@ -1,269 +1,311 @@
|
|
|
1
|
-
export const
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
system_generated:
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
1
|
+
export const default_app = {
|
|
2
|
+
meta :{
|
|
3
|
+
name:"beanbagdb_system",
|
|
4
|
+
description:"This is the default system app required for proper functioning of the database"
|
|
5
|
+
},
|
|
6
|
+
schemas:[
|
|
7
|
+
{
|
|
8
|
+
name: "schema",
|
|
9
|
+
description:"Meta-schema or the schema for defining other schemas",
|
|
10
|
+
system_generated:true,
|
|
11
|
+
version:0.70,
|
|
12
|
+
schema: {
|
|
13
|
+
type: "object",
|
|
14
|
+
additionalProperties: false,
|
|
15
|
+
properties: {
|
|
16
|
+
system_generated:{
|
|
17
|
+
type:"boolean",
|
|
18
|
+
default:false
|
|
19
|
+
},
|
|
20
|
+
version: {
|
|
21
|
+
type: "number",
|
|
22
|
+
minimum: 0,
|
|
23
|
+
default: 1,
|
|
24
|
+
description:"This is an optional field.To be used primarily for system schemas"
|
|
25
|
+
},
|
|
26
|
+
name: {
|
|
27
|
+
type: "string",
|
|
28
|
+
minLength: 4,
|
|
29
|
+
maxLength: 50,
|
|
30
|
+
pattern: "^[a-zA-Z][a-zA-Z0-9_]*$",
|
|
31
|
+
description:"This is the name of the schema.It cannot be changed later"
|
|
32
|
+
},
|
|
33
|
+
description:{
|
|
34
|
+
type:"string",
|
|
35
|
+
minLength:0,
|
|
36
|
+
maxLength:1000,
|
|
37
|
+
description:"A small description of what data in this schema stores."
|
|
38
|
+
},
|
|
39
|
+
schema: {
|
|
40
|
+
type: "object",
|
|
41
|
+
additionalProperties: true,
|
|
42
|
+
minProperties: 1,
|
|
43
|
+
maxProperties: 50,
|
|
44
|
+
description:"This must be a valid JSON Schema which will be used to validate documents created with this schema.See this https://tour.json-schema.org/",
|
|
45
|
+
},
|
|
46
|
+
settings: {
|
|
47
|
+
type: "object",
|
|
48
|
+
additionalProperties: true,
|
|
49
|
+
properties: {
|
|
50
|
+
primary_keys: {
|
|
51
|
+
type: "array",
|
|
52
|
+
default: [],
|
|
53
|
+
items: {
|
|
54
|
+
type: "string",
|
|
55
|
+
},
|
|
56
|
+
maxItems: 10,
|
|
57
|
+
description:"Fields that makes each document unique in the schema.Leave it blank if you do not need it. You can still be able to distinguish documents using the link field and the document id."
|
|
58
|
+
},
|
|
59
|
+
non_editable_fields: {
|
|
60
|
+
type: "array",
|
|
61
|
+
default: [],
|
|
62
|
+
items: {
|
|
63
|
+
type: "string",
|
|
64
|
+
},
|
|
65
|
+
maxItems: 50,
|
|
66
|
+
minItems:0,
|
|
67
|
+
description:"The list of fields whose values are added when the document is created but cannot be edited later in future."
|
|
68
|
+
},
|
|
69
|
+
encrypted_fields: {
|
|
70
|
+
type: "array",
|
|
71
|
+
default: [],
|
|
72
|
+
items: {
|
|
73
|
+
type: "string",
|
|
74
|
+
},
|
|
75
|
+
maxItems: 50,
|
|
76
|
+
description:"Once set, all the data in this field will be encrypted before storing it in the database. Encryption key must be provided during the time of BeanBagDB initialization and must be managed by the user as it is NOT stored in the database"
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
required :["primary_keys","non_editable_fields","encrypted_fields"]
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
required: ["name","description","schema", "settings"],
|
|
26
83
|
},
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
description:"A small description of what data in this schema stores."
|
|
84
|
+
settings: {
|
|
85
|
+
primary_keys: ["name"],
|
|
86
|
+
non_editable_fields:[],
|
|
87
|
+
encrypted_fields:[]
|
|
32
88
|
},
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
system_generated:true,
|
|
92
|
+
version:0.60,
|
|
93
|
+
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",
|
|
94
|
+
name: "system_key",
|
|
33
95
|
schema: {
|
|
34
96
|
type: "object",
|
|
35
97
|
additionalProperties: true,
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
98
|
+
required:["name","value"],
|
|
99
|
+
properties: {
|
|
100
|
+
name: {
|
|
101
|
+
type: "string",
|
|
102
|
+
minLength: 5,
|
|
103
|
+
maxLength: 50,
|
|
104
|
+
pattern: "^[a-zA-Z][a-zA-Z0-9_]*$",
|
|
105
|
+
},
|
|
106
|
+
value: {
|
|
107
|
+
type: "string",
|
|
108
|
+
minLength: 5,
|
|
109
|
+
maxLength: 5000,
|
|
110
|
+
pattern: "^[^\n\r]*$",
|
|
111
|
+
description:"Must be a single line string"
|
|
112
|
+
},
|
|
113
|
+
note: {
|
|
114
|
+
type: "string",
|
|
115
|
+
minLength: 1,
|
|
116
|
+
maxLength: 5000,
|
|
117
|
+
},
|
|
118
|
+
},
|
|
39
119
|
},
|
|
40
120
|
settings: {
|
|
121
|
+
primary_keys: ["name"],
|
|
122
|
+
encrypted_fields:["value"],
|
|
123
|
+
non_editable_fields:[]
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
version:0.60,
|
|
128
|
+
system_generated:true,
|
|
129
|
+
description:"The system relies on these settings for proper functioning or enabling optional features.",
|
|
130
|
+
name: "system_setting",
|
|
131
|
+
schema: {
|
|
132
|
+
required:["name","value"],
|
|
41
133
|
type: "object",
|
|
42
134
|
additionalProperties: true,
|
|
43
135
|
properties: {
|
|
44
|
-
|
|
45
|
-
type: "
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
},
|
|
50
|
-
maxItems: 10,
|
|
51
|
-
description:"Fields that makes each document unique in the schema.Leave it blank if you do not need it. You can still be able to distinguish documents using the link field and the document id."
|
|
136
|
+
name: {
|
|
137
|
+
type: "string",
|
|
138
|
+
minLength: 5,
|
|
139
|
+
maxLength: 1000,
|
|
140
|
+
pattern: "^[a-zA-Z][a-zA-Z0-9_]*$",
|
|
52
141
|
},
|
|
53
|
-
|
|
54
|
-
type: "array"
|
|
55
|
-
default: [],
|
|
56
|
-
items: {
|
|
57
|
-
type: "string",
|
|
58
|
-
},
|
|
59
|
-
maxItems: 50,
|
|
60
|
-
minItems:0,
|
|
61
|
-
description:"The list of fields whose values are added when the document is created but cannot be edited later in future."
|
|
142
|
+
value: {
|
|
143
|
+
type: ["string", "number", "boolean", "array"]
|
|
62
144
|
},
|
|
63
|
-
|
|
64
|
-
type:
|
|
65
|
-
default:
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
},
|
|
69
|
-
maxItems: 50,
|
|
70
|
-
description:"Once set, all the data in this field will be encrypted before storing it in the database. Encryption key must be provided during the time of BeanBagDB initialization and must be managed by the user as it is NOT stored in the database"
|
|
145
|
+
on_update_array:{
|
|
146
|
+
type:"string",
|
|
147
|
+
default:"replace",
|
|
148
|
+
description:"Special operation only for updating Arrays. Either replace it or append new elements to it. Cannot be edited",
|
|
149
|
+
enum:["replace","append"],
|
|
71
150
|
}
|
|
72
151
|
},
|
|
73
|
-
required :["primary_keys","non_editable_fields","encrypted_fields"]
|
|
74
152
|
},
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
primary_keys: ["name"],
|
|
80
|
-
non_editable_fields:[],
|
|
81
|
-
encrypted_fields:[]
|
|
82
|
-
},
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
export const system_schemas = {
|
|
86
|
-
keys: {
|
|
87
|
-
system_generated:true,
|
|
88
|
-
version:0.52,
|
|
89
|
-
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",
|
|
90
|
-
name: "system_key",
|
|
91
|
-
schema: {
|
|
92
|
-
type: "object",
|
|
93
|
-
additionalProperties: true,
|
|
94
|
-
required:["name","value"],
|
|
95
|
-
properties: {
|
|
96
|
-
name: {
|
|
97
|
-
type: "string",
|
|
98
|
-
minLength: 5,
|
|
99
|
-
maxLength: 50,
|
|
100
|
-
pattern: "^[a-zA-Z][a-zA-Z0-9_]*$",
|
|
101
|
-
},
|
|
102
|
-
value: {
|
|
103
|
-
type: "string",
|
|
104
|
-
minLength: 5,
|
|
105
|
-
maxLength: 5000,
|
|
106
|
-
pattern: "^[^\n\r]*$",
|
|
107
|
-
description:"Must be a single line string"
|
|
108
|
-
},
|
|
109
|
-
note: {
|
|
110
|
-
type: "string",
|
|
111
|
-
minLength: 1,
|
|
112
|
-
maxLength: 5000,
|
|
113
|
-
pattern: "^[a-zA-Z][a-zA-Z0-9_]*$",
|
|
114
|
-
},
|
|
153
|
+
settings: {
|
|
154
|
+
primary_keys: ["name"],
|
|
155
|
+
non_editable_fields: ["name"],
|
|
156
|
+
encrypted_fields:[]
|
|
115
157
|
},
|
|
116
158
|
},
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
159
|
+
{
|
|
160
|
+
name:"system_edge_constraint",
|
|
161
|
+
system_generated:true,
|
|
162
|
+
version:0.50,
|
|
163
|
+
description: "To define edge constraints for simple directed graph of records.",
|
|
164
|
+
schema:{
|
|
165
|
+
type: "object",
|
|
166
|
+
additionalProperties: true,
|
|
167
|
+
required:["node1","node2","edge_type"],
|
|
168
|
+
properties: {
|
|
169
|
+
node1: {
|
|
170
|
+
type: "string",
|
|
171
|
+
minLength: 1,
|
|
172
|
+
maxLength: 500,
|
|
173
|
+
pattern: "^(\\*|(\\*-[a-zA-Z0-9_-]+)(,[a-zA-Z0-9_-]+)*|[a-zA-Z0-9_-]+(,[a-zA-Z0-9_-]+)*)$"
|
|
174
|
+
},
|
|
175
|
+
node2: {
|
|
176
|
+
type: "string",
|
|
177
|
+
minLength: 1,
|
|
178
|
+
maxLength: 500,
|
|
179
|
+
pattern: "^(\\*|(\\*-[a-zA-Z0-9_-]+)(,[a-zA-Z0-9_-]+)*|[a-zA-Z0-9_-]+(,[a-zA-Z0-9_-]+)*)$"
|
|
180
|
+
},
|
|
181
|
+
name:{
|
|
182
|
+
type: "string",
|
|
183
|
+
minLength: 1,
|
|
184
|
+
maxLength: 500,
|
|
185
|
+
pattern: "^[a-zA-Z][a-zA-Z0-9_]*$",
|
|
186
|
+
},
|
|
187
|
+
label:{
|
|
188
|
+
type: "string",
|
|
189
|
+
maxLength: 500,
|
|
190
|
+
},
|
|
191
|
+
note:{
|
|
192
|
+
type: "string",
|
|
193
|
+
maxLength: 5000,
|
|
194
|
+
},
|
|
195
|
+
max_from_node1:{
|
|
196
|
+
type:"number",
|
|
197
|
+
default: -1,
|
|
198
|
+
},
|
|
199
|
+
max_to_node2:{
|
|
200
|
+
type:"number",
|
|
201
|
+
default: -1,
|
|
202
|
+
}
|
|
147
203
|
}
|
|
148
204
|
},
|
|
205
|
+
settings: {
|
|
206
|
+
primary_keys: ["name"],
|
|
207
|
+
non_editable_fields:["name"],
|
|
208
|
+
encrypted_fields:[]
|
|
209
|
+
},
|
|
149
210
|
},
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
maxLength: 500,
|
|
170
|
-
pattern: "^(\\*|(\\*-[a-zA-Z0-9_-]+)(,[a-zA-Z0-9_-]+)*|[a-zA-Z0-9_-]+(,[a-zA-Z0-9_-]+)*)$"
|
|
171
|
-
},
|
|
172
|
-
node2: {
|
|
173
|
-
type: "string",
|
|
174
|
-
minLength: 1,
|
|
175
|
-
maxLength: 500,
|
|
176
|
-
pattern: "^(\\*|(\\*-[a-zA-Z0-9_-]+)(,[a-zA-Z0-9_-]+)*|[a-zA-Z0-9_-]+(,[a-zA-Z0-9_-]+)*)$"
|
|
177
|
-
},
|
|
178
|
-
name:{
|
|
179
|
-
type: "string",
|
|
180
|
-
minLength: 1,
|
|
181
|
-
maxLength: 500,
|
|
182
|
-
pattern: "^[a-zA-Z][a-zA-Z0-9_]*$",
|
|
183
|
-
},
|
|
184
|
-
label:{
|
|
185
|
-
type: "string",
|
|
186
|
-
maxLength: 500,
|
|
187
|
-
},
|
|
188
|
-
note:{
|
|
189
|
-
type: "string",
|
|
190
|
-
maxLength: 5000,
|
|
191
|
-
},
|
|
192
|
-
max_from_node1:{
|
|
193
|
-
type:"number",
|
|
194
|
-
default: -1,
|
|
195
|
-
},
|
|
196
|
-
max_to_node2:{
|
|
197
|
-
type:"number",
|
|
198
|
-
default: -1,
|
|
211
|
+
{
|
|
212
|
+
name:"system_edge",
|
|
213
|
+
system_generated:true,
|
|
214
|
+
version:0.50,
|
|
215
|
+
description: "To define edges in the simple directed graph of records.",
|
|
216
|
+
schema:{
|
|
217
|
+
type: "object",
|
|
218
|
+
additionalProperties: true,
|
|
219
|
+
required:["node1","node2","edge_type"],
|
|
220
|
+
properties: {
|
|
221
|
+
node1: {
|
|
222
|
+
type: "string",
|
|
223
|
+
},
|
|
224
|
+
node2: {
|
|
225
|
+
type: "string",
|
|
226
|
+
},
|
|
227
|
+
edge_name:{
|
|
228
|
+
type: "string",
|
|
229
|
+
}
|
|
199
230
|
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
231
|
+
},
|
|
232
|
+
settings: {
|
|
233
|
+
primary_keys: ["node1","node2","edge_type"],
|
|
234
|
+
non_editable_fields:["edge_type"],
|
|
235
|
+
encrypted_fields:[]
|
|
236
|
+
},
|
|
206
237
|
},
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
238
|
+
{
|
|
239
|
+
name:"system_media",
|
|
240
|
+
system_generated:true,
|
|
241
|
+
version:0.60,
|
|
242
|
+
description: "To store images as Base64",
|
|
243
|
+
schema:{
|
|
244
|
+
type: "object",
|
|
245
|
+
additionalProperties: true,
|
|
246
|
+
required:["imageBase64","caption","source"],
|
|
247
|
+
properties: {
|
|
248
|
+
imageBase64: {
|
|
249
|
+
type: "string",
|
|
250
|
+
"media": {
|
|
251
|
+
"binaryEncoding": "base64"
|
|
252
|
+
}
|
|
253
|
+
},
|
|
254
|
+
caption: {
|
|
255
|
+
type: "string",
|
|
256
|
+
},
|
|
257
|
+
source:{
|
|
258
|
+
type: "string",
|
|
259
|
+
}
|
|
226
260
|
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
261
|
+
},
|
|
262
|
+
settings: {
|
|
263
|
+
primary_keys: ["caption"],
|
|
264
|
+
non_editable_fields:[],
|
|
265
|
+
encrypted_fields:[]
|
|
266
|
+
},
|
|
233
267
|
},
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
268
|
+
{
|
|
269
|
+
name:"system_log",
|
|
270
|
+
system_generated:true,
|
|
271
|
+
version:0.50,
|
|
272
|
+
description: "To define edges in the simple directed graph of records.",
|
|
273
|
+
schema:{
|
|
274
|
+
type: "object",
|
|
275
|
+
additionalProperties: true,
|
|
276
|
+
required:["text"],
|
|
277
|
+
properties: {
|
|
278
|
+
text: {
|
|
279
|
+
type: "string",
|
|
280
|
+
},
|
|
281
|
+
data: {
|
|
282
|
+
type: "object",
|
|
283
|
+
additionalProperties: true,
|
|
284
|
+
},
|
|
285
|
+
app:{
|
|
286
|
+
type: "string",
|
|
287
|
+
},
|
|
288
|
+
time:{
|
|
289
|
+
type:"string"
|
|
290
|
+
}
|
|
253
291
|
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
292
|
+
},
|
|
293
|
+
settings: {
|
|
294
|
+
primary_keys: [],
|
|
295
|
+
non_editable_fields:[],
|
|
296
|
+
encrypted_fields:[]
|
|
297
|
+
},
|
|
260
298
|
},
|
|
261
|
-
|
|
262
|
-
|
|
299
|
+
],
|
|
300
|
+
records:[]
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
|
|
263
304
|
|
|
264
305
|
// this is not stored in the DB. only for validating the metadata during doc update
|
|
265
306
|
export const editable_metadata_schema = {
|
|
266
307
|
additionalProperties: false,
|
|
308
|
+
type:"object",
|
|
267
309
|
properties:{
|
|
268
310
|
tags:{
|
|
269
311
|
type:"array",
|
package/test/operations.test.js
CHANGED
|
@@ -1656,7 +1656,7 @@ describe("Doc search tests", async () => {
|
|
|
1656
1656
|
it('all docs', async () => {
|
|
1657
1657
|
try {
|
|
1658
1658
|
let udata = await database3.search({selector:{}})
|
|
1659
|
-
assert(udata.docs.length==
|
|
1659
|
+
assert(udata.docs.length==12)
|
|
1660
1660
|
} catch (error) {
|
|
1661
1661
|
//console.log(error)
|
|
1662
1662
|
throw error
|
|
@@ -1676,7 +1676,7 @@ describe("Doc search tests", async () => {
|
|
|
1676
1676
|
it('read docs 2', async () => {
|
|
1677
1677
|
try {
|
|
1678
1678
|
let udata = await database3.search({selector:{"schema":"schema"}})
|
|
1679
|
-
assert(udata.docs.length==
|
|
1679
|
+
assert(udata.docs.length==8) // schema,book,setting,key,edge,edge_constraints
|
|
1680
1680
|
} catch (error) {
|
|
1681
1681
|
//console.log(error)
|
|
1682
1682
|
throw error
|