beanbagdb 0.5.51 → 0.5.53
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/README.md +7 -129
- package/doc-src/0_about.md +115 -0
- package/doc-src/1_getting-started.md +1 -0
- package/doc-src/2_schema.md +1 -0
- package/doc-src/3_plugins.md +1 -0
- package/doc-src/contents.json +15 -0
- package/jsdoc.json +1 -1
- package/package.json +4 -2
- package/src/index.js +887 -526
- package/src/system_schema.js +35 -5
- package/test/couchdb.js +2 -2
- package/test/operations.test.js +1687 -286
- package/test/pouchdb.js +12 -6
- package/test/test1.js +133 -176
- /package/{docs → doc-src}/logo.png +0 -0
package/test/pouchdb.js
CHANGED
|
@@ -41,19 +41,25 @@ const pdb = new PouchDB(dbname);
|
|
|
41
41
|
},
|
|
42
42
|
},
|
|
43
43
|
utils: {
|
|
44
|
-
encrypt: (text, encryptionKey) => {
|
|
44
|
+
encrypt: async (text, encryptionKey) => {
|
|
45
|
+
//console.log(encryptionKey)
|
|
45
46
|
const key = scryptSync(encryptionKey, "salt", 32); // Derive a 256-bit key
|
|
46
47
|
const iv = randomBytes(16); // Initialization vector
|
|
47
48
|
const cipher = createCipheriv("aes-256-cbc", key, iv);
|
|
48
49
|
let encrypted = cipher.update(text, "utf8", "hex");
|
|
49
50
|
encrypted += cipher.final("hex");
|
|
50
|
-
|
|
51
|
+
//console.log("IV:", iv.toString("hex"));
|
|
52
|
+
//console.log("Encrypted:", encrypted);
|
|
53
|
+
return iv.toString("hex") + ":" + encrypted; // Prepend the IV for decryption
|
|
51
54
|
},
|
|
52
|
-
decrypt: (encryptedText, encryptionKey) => {
|
|
55
|
+
decrypt: async (encryptedText, encryptionKey) => {
|
|
56
|
+
//console.log(encryptedText, encryptionKey)
|
|
53
57
|
const key = scryptSync(encryptionKey, "salt", 32); // Derive a 256-bit key
|
|
54
|
-
const [
|
|
55
|
-
|
|
56
|
-
|
|
58
|
+
const [ivHex, encryptedHex] = encryptedText.split(":");
|
|
59
|
+
const iv = Buffer.from(ivHex, "hex");
|
|
60
|
+
const encrypted = Buffer.from(encryptedHex, "hex");
|
|
61
|
+
//console.log("IV:", iv.toString("hex"));
|
|
62
|
+
//console.log("Encrypted:", encrypted.toString("hex"));
|
|
57
63
|
const decipher = createDecipheriv("aes-256-cbc", key, iv);
|
|
58
64
|
let decrypted = decipher.update(encrypted, "hex", "utf8");
|
|
59
65
|
decrypted += decipher.final("utf8");
|
package/test/test1.js
CHANGED
|
@@ -1,160 +1,3 @@
|
|
|
1
|
-
// // require("dotenv").config();
|
|
2
|
-
// import 'dotenv/config'
|
|
3
|
-
// // import * as cbbdb from "../src/couchdb.js"
|
|
4
|
-
// // const cbbdb = require("../src/couchdb.js");
|
|
5
|
-
// // const pbbdb = require("../src/pouchdb.js");
|
|
6
|
-
// import BeanBagDB_PouchDB from "../src/pouchdb.js";
|
|
7
|
-
// import BeanBagDB_CouchDB from "../src/couchdb.js";
|
|
8
|
-
// // const pl1 = require("./helper.js")
|
|
9
|
-
|
|
10
|
-
// (async()=>{
|
|
11
|
-
// // console.log(process.env.cdburl)
|
|
12
|
-
// let db = new BeanBagDB_CouchDB(process.env.cdburl, process.env.cdbname, "sample_key");
|
|
13
|
-
// try {
|
|
14
|
-
// await db.ready();
|
|
15
|
-
// await db.initialize_db();
|
|
16
|
-
// await db.update_indexes()
|
|
17
|
-
// } catch (error) {
|
|
18
|
-
// console.log(error);
|
|
19
|
-
// }
|
|
20
|
-
// })()
|
|
21
|
-
|
|
22
|
-
// async function main1() {
|
|
23
|
-
// let db = new cbbdb(process.env.cdburl, process.env.cdbname, "sample_key");
|
|
24
|
-
|
|
25
|
-
// try {
|
|
26
|
-
// await db.ready();
|
|
27
|
-
// await db.initialize_db();
|
|
28
|
-
// await db.update_indexes()
|
|
29
|
-
// } catch (error) {
|
|
30
|
-
// console.log(error);
|
|
31
|
-
// }
|
|
32
|
-
// }
|
|
33
|
-
|
|
34
|
-
// async function main2() {
|
|
35
|
-
// let db = new cbbdb(process.env.cdburl, process.env.cdbname, "sample_key");
|
|
36
|
-
// await db.ready();
|
|
37
|
-
// // await db.update_indexes()
|
|
38
|
-
// sample_setting_docs = [
|
|
39
|
-
// {
|
|
40
|
-
// name: "sample1",
|
|
41
|
-
// value: "sample thing here",
|
|
42
|
-
// },
|
|
43
|
-
// {
|
|
44
|
-
// name: "no_value",
|
|
45
|
-
// },
|
|
46
|
-
// {
|
|
47
|
-
// value: "incorrect name",
|
|
48
|
-
// },
|
|
49
|
-
// {
|
|
50
|
-
// name: "sample1",
|
|
51
|
-
// value: "sample thing here",
|
|
52
|
-
// },
|
|
53
|
-
// {
|
|
54
|
-
// name: "sample1",
|
|
55
|
-
// value: "primary key check",
|
|
56
|
-
// },
|
|
57
|
-
// {
|
|
58
|
-
// name: "Sample2",
|
|
59
|
-
// value: "normal insert",
|
|
60
|
-
// },
|
|
61
|
-
// {
|
|
62
|
-
// value: "No name provided",
|
|
63
|
-
// },
|
|
64
|
-
// ];
|
|
65
|
-
// let t = sample_setting_docs.length
|
|
66
|
-
// for (let i = 0; i < t; i++) {
|
|
67
|
-
// try {
|
|
68
|
-
// let newid = await db.insert("system_settings",sample_setting_docs[i])
|
|
69
|
-
// console.log(newid)
|
|
70
|
-
// } catch (error) {
|
|
71
|
-
// console.log("Error "+i)
|
|
72
|
-
// console.error(error)
|
|
73
|
-
// continue
|
|
74
|
-
// }
|
|
75
|
-
// }
|
|
76
|
-
// }
|
|
77
|
-
|
|
78
|
-
// async function main3() {
|
|
79
|
-
// let db = new cbbdb(process.env.cdburl, process.env.cdbname, "sample_key");
|
|
80
|
-
// await db.ready();
|
|
81
|
-
// // await db.update_indexes()
|
|
82
|
-
// sample_setting_docs = [
|
|
83
|
-
// {
|
|
84
|
-
// name: "sample1",
|
|
85
|
-
// value: "sample thing here",
|
|
86
|
-
// },
|
|
87
|
-
// {
|
|
88
|
-
// name: "sample2",
|
|
89
|
-
// value: "sample thing here again",
|
|
90
|
-
// },
|
|
91
|
-
|
|
92
|
-
// {
|
|
93
|
-
// name: "sample1",
|
|
94
|
-
// value: "sample thing here again",
|
|
95
|
-
// },
|
|
96
|
-
// ];
|
|
97
|
-
// let t = sample_setting_docs.length
|
|
98
|
-
// for (let i = 0; i < t; i++) {
|
|
99
|
-
// try {
|
|
100
|
-
// let newid = await db.insert("system_keys",sample_setting_docs[i])
|
|
101
|
-
// console.log(newid)
|
|
102
|
-
// } catch (error) {
|
|
103
|
-
// console.log("Error "+i)
|
|
104
|
-
// console.error(error)
|
|
105
|
-
// continue
|
|
106
|
-
// }
|
|
107
|
-
// }
|
|
108
|
-
// }
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
// async function main4(){
|
|
112
|
-
// let db = new cbbdb(process.env.cdburl, process.env.cdbname, "sample_key");
|
|
113
|
-
// await db.ready();
|
|
114
|
-
// let doc1 = await db.get("e94b5eebe6b3c6dab8e2508d5908717c")
|
|
115
|
-
// console.log(doc1)
|
|
116
|
-
// let doc2 = await db.get_doc("system_keys",{"name":"sample2"})
|
|
117
|
-
// console.log(doc2)
|
|
118
|
-
// let doc3 = await db.get_doc("system_logs")
|
|
119
|
-
// console.log(doc3)
|
|
120
|
-
// }
|
|
121
|
-
|
|
122
|
-
// async function main5(){
|
|
123
|
-
// let db = new cbbdb(process.env.cdburl, process.env.cdbname, "sample_key");
|
|
124
|
-
// await db.ready();
|
|
125
|
-
// let id = "e94b5eebe6b3c6dab8e2508d5908717c"
|
|
126
|
-
// let rec_1 = await db.get(id)
|
|
127
|
-
// let rec1 = rec_1.doc
|
|
128
|
-
// console.log(rec1)
|
|
129
|
-
// let rec1u = await db.update(id,"",{data:{"value":"secret key updated"},meta:{tags:["testing1","testing2","money"]}})
|
|
130
|
-
// console.log(rec1u)
|
|
131
|
-
// let r1 = await db.get(id)
|
|
132
|
-
// console.log(r1)
|
|
133
|
-
// }
|
|
134
|
-
|
|
135
|
-
// async function main6(){
|
|
136
|
-
// let db = new pbbdb(process.env.cdburl, process.env.cdbname, "sample_key");
|
|
137
|
-
// await db.ready()
|
|
138
|
-
// //await db.initialize_db()
|
|
139
|
-
|
|
140
|
-
// }
|
|
141
|
-
|
|
142
|
-
// // main1().then(() => {console.log("Bye.");}).catch();
|
|
143
|
-
|
|
144
|
-
// // main3().then(() => {console.log("Bye.");}).catch();
|
|
145
|
-
|
|
146
|
-
// // main4().then(() => {console.log("Bye.");}).catch();
|
|
147
|
-
|
|
148
|
-
// // main5().then(() => {console.log("Bye.");}).catch();
|
|
149
|
-
|
|
150
|
-
// // main6().then(() => {console.log("Bye.");}).catch();
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
// // (async ()=>{
|
|
154
|
-
// // let db = new cbbdb(process.env.cdburl, process.env.cdbname, "sample_key");
|
|
155
|
-
// // await db.ready();
|
|
156
|
-
// // db.load_plugin("sample",pl1)
|
|
157
|
-
// // })();
|
|
158
1
|
|
|
159
2
|
import { get_pdb_doc } from './pouchdb.js';
|
|
160
3
|
import { throws, strictEqual } from "assert";
|
|
@@ -162,25 +5,139 @@ import {BeanBagDB} from '../src/index.js';
|
|
|
162
5
|
|
|
163
6
|
(async()=>{
|
|
164
7
|
|
|
165
|
-
let schema_docs_invalid = [
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
8
|
+
// let schema_docs_invalid = [
|
|
9
|
+
// {
|
|
10
|
+
// name: "",
|
|
11
|
+
// description: "",
|
|
12
|
+
// schema: {},
|
|
13
|
+
// settings: {},
|
|
14
|
+
// }
|
|
15
|
+
// ]
|
|
16
|
+
let doc_obj = get_pdb_doc("test_database_27","qwertyuiopaqwsde1254")
|
|
17
|
+
let database1 = new BeanBagDB(doc_obj);
|
|
18
|
+
// await database.ready()
|
|
19
|
+
// let a = await database.create("schema",schema_docs_invalid[0])
|
|
20
|
+
|
|
21
|
+
const test_schema = {
|
|
22
|
+
name:"book",
|
|
23
|
+
description:"Test schema 1",
|
|
24
|
+
schema: {
|
|
25
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
26
|
+
type: "object",
|
|
27
|
+
properties: {
|
|
28
|
+
title: {
|
|
29
|
+
type: "string",
|
|
30
|
+
minLength: 1,
|
|
31
|
+
description: "The title of the book",
|
|
32
|
+
},
|
|
33
|
+
author: {
|
|
34
|
+
type: "string",
|
|
35
|
+
minLength: 1,
|
|
36
|
+
description: "The author of the book",
|
|
37
|
+
},
|
|
38
|
+
isbn: {
|
|
39
|
+
type: "string",
|
|
40
|
+
pattern: "^(97(8|9))?\\d{9}(\\d|X)$",
|
|
41
|
+
description: "The ISBN of the book, can be 10 or 13 digits",
|
|
42
|
+
},
|
|
43
|
+
publicationYear: {
|
|
44
|
+
type: "integer",
|
|
45
|
+
minimum: 1450,
|
|
46
|
+
maximum: 2024,
|
|
47
|
+
description:
|
|
48
|
+
"The year the book was published (between 1450 and 2024)",
|
|
49
|
+
},
|
|
50
|
+
genre: {
|
|
51
|
+
type: "string",
|
|
52
|
+
enum: [
|
|
53
|
+
"Fiction",
|
|
54
|
+
"Non-Fiction",
|
|
55
|
+
"Science",
|
|
56
|
+
"History",
|
|
57
|
+
"Fantasy",
|
|
58
|
+
"Biography",
|
|
59
|
+
"Children",
|
|
60
|
+
"Mystery",
|
|
61
|
+
"Horror",
|
|
62
|
+
],
|
|
63
|
+
description: "The genre of the book",
|
|
64
|
+
},
|
|
65
|
+
language: {
|
|
66
|
+
type: "string",
|
|
67
|
+
description: "The language of the book",
|
|
68
|
+
default: "English",
|
|
69
|
+
},
|
|
70
|
+
publisher: {
|
|
71
|
+
type: "string",
|
|
72
|
+
description: "The publisher of the book",
|
|
73
|
+
minLength: 1,
|
|
74
|
+
},
|
|
75
|
+
pages: {
|
|
76
|
+
type: "integer",
|
|
77
|
+
minimum: 1,
|
|
78
|
+
description: "The number of pages in the book",
|
|
79
|
+
},
|
|
80
|
+
secret: {
|
|
81
|
+
type: "string",
|
|
82
|
+
description: "Super secret related to the book",
|
|
83
|
+
minLength: 1,
|
|
84
|
+
},
|
|
179
85
|
},
|
|
86
|
+
required: ["title", "author", "isbn", "publicationYear", "genre"],
|
|
87
|
+
additionalProperties: false,
|
|
88
|
+
},
|
|
89
|
+
settings : {
|
|
90
|
+
primary_keys:['title','author'],
|
|
91
|
+
encrypted_fields:['secret'],
|
|
92
|
+
non_editable_fields:[],
|
|
93
|
+
single_record:false
|
|
180
94
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
await
|
|
185
|
-
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
await database1.ready(); // Ensure the database is ready before running tests
|
|
99
|
+
|
|
100
|
+
try {
|
|
101
|
+
//console.log(test_schema)
|
|
102
|
+
let a = await database1.create("schema",test_schema)
|
|
103
|
+
|
|
104
|
+
} catch (error) {
|
|
105
|
+
console.log("error in before")
|
|
106
|
+
console.log(error)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const book1 = {
|
|
110
|
+
title: "Harry Potter",
|
|
111
|
+
author: "J.K. Rowling",
|
|
112
|
+
isbn: "9780439139601",
|
|
113
|
+
publicationYear: 1999,
|
|
114
|
+
genre: "Fantasy",
|
|
115
|
+
publisher: "ABC DEF",
|
|
116
|
+
secret: "Super secret 1"
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
let d
|
|
120
|
+
try {
|
|
121
|
+
d = await database1.create("book", book1,{link:"sample1"});
|
|
122
|
+
console.log(d)
|
|
123
|
+
let rec = await database1.read({"_id":d._id});
|
|
124
|
+
console.log(rec)
|
|
125
|
+
|
|
126
|
+
let e = await database1.create("book", {...book1,title:"Something"},{link:"sample2"});
|
|
127
|
+
console.log(e)
|
|
128
|
+
|
|
129
|
+
} catch (error) {
|
|
130
|
+
console.log(error)
|
|
131
|
+
throw error
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
try {
|
|
136
|
+
let s = await database1.search({selector:{}})
|
|
137
|
+
console.log(s.docs.length)
|
|
138
|
+
//console.log( JSON.stringify(s,null,2))
|
|
139
|
+
} catch (error) {
|
|
140
|
+
console.log(error)
|
|
141
|
+
}
|
|
142
|
+
|
|
186
143
|
})()
|
|
File without changes
|