beanbagdb 0.5.61 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "beanbagdb",
3
- "version": "0.5.61",
3
+ "version": "0.5.70",
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
@@ -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 `system_settings.beanbagdb_version` document.
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: "system_settings", "data.name": "beanbagdb_version" },
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
- this.active = doc["data"]["value"] == this._version;
132
- this.meta.beanbagdb_version_db = doc["data"]["value"];
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 schema = await this.get("schema",{name:"schema"});
163
- if (schema["data"]["version"] != sys_sch.schema_schema.version) {
164
- logs.push("old schema_schema v " + schema["data"]["version"]);
165
- let full_doc = await this.db_api.get(schema["_id"]);
166
- full_doc["data"] = { ...sys_sch.schema_schema };
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
- // console.log(error);
173
- if (error instanceof DocNotFoundError) {
174
- // inserting new schema_schema doc
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
- let keys = Object.keys(sys_sch.system_schemas);
183
- for (let index = 0; index < keys.length; index++) {
184
- const schema_name = sys_sch.system_schemas[keys[index]]["name"];
185
- const schema_data = sys_sch.system_schemas[keys[index]];
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
- logs.push("old " + schema_name + " v " + schema1["data"]["version"]);
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
- logs.push("new " + schema_name + " v " + schema_data.version);
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
- let new_schema_doc = this._get_blank_schema_doc(
202
- "schema",
203
- sys_sch.schema_schema["schema"],
204
- schema_data
205
- );
206
- await this.db_api.insert(new_schema_doc);
207
- logs.push("init " + schema_name + " v " + schema_data.version);
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
- this.meta.beanbagdb_version_db = this._version;
226
- this.active = true;
227
- console.log(logs.join(","))
228
- } else {
229
- // no new updates were done
230
- console.log("Database already up to date");
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
+ }
231
267
  }
232
- }
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")
277
+ }
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: "system_settings", "data.name": name },
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("system_settings");
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 = sys_sch.schema_schema.version;
787
- let keys = Object.keys(sys_sch.system_schemas).map((item) => {
788
- sum = sum + sys_sch.system_schemas[item].version;
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
  }
@@ -1,267 +1,306 @@
1
- export const schema_schema = {
2
- name: "schema",
3
- description:"Meta-schema or the schema for defining other schemas",
4
- system_generated:true,
5
- version:0.56,
6
- schema: {
7
- type: "object",
8
- additionalProperties: false,
9
- properties: {
10
- system_generated:{
11
- type:"boolean",
12
- default:false
13
- },
14
- version: {
15
- type: "number",
16
- minimum: 0,
17
- default: 1,
18
- description:"This is an optional field.To be used primarily for system schemas"
19
- },
20
- name: {
21
- type: "string",
22
- minLength: 4,
23
- maxLength: 50,
24
- pattern: "^[a-zA-Z][a-zA-Z0-9_]*$",
25
- description:"This is the name of the schema.It cannot be changed later"
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
- description:{
28
- type:"string",
29
- minLength:0,
30
- maxLength:1000,
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
- minProperties: 1,
37
- maxProperties: 50,
38
- 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/",
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
- primary_keys: {
45
- type: "array",
46
- default: [],
47
- items: {
48
- type: "string",
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
- non_editable_fields: {
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
- encrypted_fields: {
64
- type: "array",
65
- default: [],
66
- items: {
67
- type: "string",
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
- required: ["name","description","schema", "settings"],
77
- },
78
- settings: {
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.53,
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
- },
153
+ settings: {
154
+ primary_keys: ["name"],
155
+ non_editable_fields: ["name"],
156
+ encrypted_fields:[]
114
157
  },
115
158
  },
116
- settings: {
117
- primary_keys: ["name"],
118
- encrypted_fields:["value"],
119
- non_editable_fields:[]
120
- },
121
- },
122
- settings: {
123
- version:0.5,
124
- system_generated:true,
125
- description:"The system relies on these settings for proper functioning or enabling optional features.",
126
- name: "system_setting",
127
- schema: {
128
- required:["name","value"],
129
- type: "object",
130
- additionalProperties: true,
131
- properties: {
132
- name: {
133
- type: "string",
134
- minLength: 5,
135
- maxLength: 1000,
136
- pattern: "^[a-zA-Z][a-zA-Z0-9_]*$",
137
- },
138
- value: {
139
- type: ["string", "number", "boolean", "array"]
140
- },
141
- on_update_array:{
142
- type:"string",
143
- default:"replace",
144
- description:"Special operation only for updating Arrays. Either replace it or append new elements to it. Cannot be edited",
145
- enum:["replace","append"],
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
+ }
146
203
  }
147
204
  },
205
+ settings: {
206
+ primary_keys: ["name"],
207
+ non_editable_fields:["name"],
208
+ encrypted_fields:[]
209
+ },
148
210
  },
149
- settings: {
150
- primary_keys: ["name"],
151
- non_editable_fields: ["name"],
152
- encrypted_fields:[]
153
- },
154
- },
155
- edges_constraints:{
156
- name:"system_edge_constraint",
157
- system_generated:true,
158
- version:0.5,
159
- description: "To define edge constraints for simple directed graph of records.",
160
- schema:{
161
- type: "object",
162
- additionalProperties: true,
163
- required:["node1","node2","edge_type"],
164
- properties: {
165
- node1: {
166
- type: "string",
167
- minLength: 1,
168
- maxLength: 500,
169
- pattern: "^(\\*|(\\*-[a-zA-Z0-9_-]+)(,[a-zA-Z0-9_-]+)*|[a-zA-Z0-9_-]+(,[a-zA-Z0-9_-]+)*)$"
170
- },
171
- node2: {
172
- type: "string",
173
- minLength: 1,
174
- maxLength: 500,
175
- pattern: "^(\\*|(\\*-[a-zA-Z0-9_-]+)(,[a-zA-Z0-9_-]+)*|[a-zA-Z0-9_-]+(,[a-zA-Z0-9_-]+)*)$"
176
- },
177
- name:{
178
- type: "string",
179
- minLength: 1,
180
- maxLength: 500,
181
- pattern: "^[a-zA-Z][a-zA-Z0-9_]*$",
182
- },
183
- label:{
184
- type: "string",
185
- maxLength: 500,
186
- },
187
- note:{
188
- type: "string",
189
- maxLength: 5000,
190
- },
191
- max_from_node1:{
192
- type:"number",
193
- default: -1,
194
- },
195
- max_to_node2:{
196
- type:"number",
197
- 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
+ }
198
230
  }
199
- }
200
- },
201
- settings: {
202
- primary_keys: ["name"],
203
- non_editable_fields:["name"],
204
- encrypted_fields:[]
231
+ },
232
+ settings: {
233
+ primary_keys: ["node1","node2","edge_type"],
234
+ non_editable_fields:["edge_type"],
235
+ encrypted_fields:[]
236
+ },
205
237
  },
206
- },
207
- edges:{
208
- name:"system_edge",
209
- system_generated:true,
210
- version:0.5,
211
- description: "To define edges in the simple directed graph of records.",
212
- schema:{
213
- type: "object",
214
- additionalProperties: true,
215
- required:["node1","node2","edge_type"],
216
- properties: {
217
- node1: {
218
- type: "string",
219
- },
220
- node2: {
221
- type: "string",
222
- },
223
- edge_name:{
224
- type: "string",
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
+ }
225
260
  }
226
- }
227
- },
228
- settings: {
229
- primary_keys: ["node1","node2","edge_type"],
230
- non_editable_fields:["edge_type"],
231
- encrypted_fields:[]
261
+ },
262
+ settings: {
263
+ primary_keys: ["caption"],
264
+ non_editable_fields:[],
265
+ encrypted_fields:[]
266
+ },
232
267
  },
233
- },
234
- media:{
235
- name:"system_media",
236
- system_generated:true,
237
- version:0.5,
238
- description: "To store images as Base64",
239
- schema:{
240
- type: "object",
241
- additionalProperties: true,
242
- required:["imageBase64","caption","source"],
243
- properties: {
244
- imageBase64: {
245
- type: "string",
246
- "media": {
247
- "binaryEncoding": "base64"
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"
248
290
  }
249
- },
250
- caption: {
251
- type: "string",
252
- },
253
- source:{
254
- type: "string",
255
291
  }
256
- }
257
- },
258
- settings: {
259
- primary_keys: ["caption"],
260
- non_editable_fields:[],
261
- encrypted_fields:[]
292
+ },
293
+ settings: {
294
+ primary_keys: [],
295
+ non_editable_fields:[],
296
+ encrypted_fields:[]
297
+ },
262
298
  },
263
- }
264
- };
299
+ ],
300
+ records:[]
301
+ }
302
+
303
+
265
304
 
266
305
  // this is not stored in the DB. only for validating the metadata during doc update
267
306
  export const editable_metadata_schema = {
@@ -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==11)
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==7) // schema,book,setting,key,edge,edge_constraints
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