beanbagdb 0.5.41 → 0.5.43
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/dist/bundle.browser.js +24052 -0
- package/dist/bundle.node.js +8333 -0
- package/package.json +8 -5
- package/.github/workflows/release.yml +0 -41
- package/dist/beanbagdb.esm.js +0 -153304
- package/dist/beanbagdb.esm.js.map +0 -1
- package/docs/logo.png +0 -0
- package/rollup.config.js +0 -47
- package/src/beanbagdb.js +0 -580
- package/src/couchdb.js +0 -64
- package/src/index.js +0 -6
- package/src/pouchdb.js +0 -68
- package/src/system_schema.js +0 -180
- package/src/utils.js +0 -45
- package/test/init.test.js +0 -219
- package/test/operations.test.js +0 -1
- package/test/test1.js +0 -157
package/src/pouchdb.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import PouchDB from 'pouchdb';
|
|
2
|
-
import pouchdbFind from 'pouchdb-find';
|
|
3
|
-
PouchDB.plugin(pouchdbFind)
|
|
4
|
-
|
|
5
|
-
import { scryptSync, randomBytes, createCipheriv, createDecipheriv } from 'crypto';
|
|
6
|
-
import BeanBagDB from "./beanbagdb.js";
|
|
7
|
-
|
|
8
|
-
class BeanBagDB_PouchDB extends BeanBagDB {
|
|
9
|
-
constructor(db_url,db_name,encryption_key){
|
|
10
|
-
const pdb = new PouchDB(db_name);
|
|
11
|
-
const doc_obj = {
|
|
12
|
-
name: db_name,
|
|
13
|
-
encryption_key: encryption_key,
|
|
14
|
-
api:{
|
|
15
|
-
insert: async (doc)=>{
|
|
16
|
-
const result = await pdb.post(doc)
|
|
17
|
-
return result
|
|
18
|
-
},
|
|
19
|
-
// delete: ()=>{db1.destroy},
|
|
20
|
-
update: async (doc)=>{
|
|
21
|
-
const result = await pdb.put(doc)
|
|
22
|
-
return result
|
|
23
|
-
},
|
|
24
|
-
search: async (query)=>{
|
|
25
|
-
const results = await pdb.find(query)
|
|
26
|
-
return results // of the form {docs:[],...}
|
|
27
|
-
},
|
|
28
|
-
get: async (id)=>{
|
|
29
|
-
const data = await pdb.get(id)
|
|
30
|
-
return data
|
|
31
|
-
},
|
|
32
|
-
delete:async (id)=>{
|
|
33
|
-
const doc = await pdb.get(id)
|
|
34
|
-
const resp = await pdb.remove(doc)
|
|
35
|
-
return resp
|
|
36
|
-
},
|
|
37
|
-
createIndex: async (filter)=>{
|
|
38
|
-
const data = await pdb.createIndex(filter)
|
|
39
|
-
return data
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
utils:{
|
|
43
|
-
encrypt: (text,encryptionKey)=>{
|
|
44
|
-
const key = scryptSync(encryptionKey, 'salt', 32); // Derive a 256-bit key
|
|
45
|
-
const iv = randomBytes(16); // Initialization vector
|
|
46
|
-
const cipher = createCipheriv('aes-256-cbc', key, iv);
|
|
47
|
-
let encrypted = cipher.update(text, 'utf8', 'hex');
|
|
48
|
-
encrypted += cipher.final('hex');
|
|
49
|
-
return iv.toString('hex') + ':' + encrypted; // Prepend the IV for later use
|
|
50
|
-
},
|
|
51
|
-
decrypt : (encryptedText, encryptionKey)=>{
|
|
52
|
-
const key = scryptSync(encryptionKey, 'salt', 32); // Derive a 256-bit key
|
|
53
|
-
const [iv, encrypted] = encryptedText.split(':').map(part => Buffer.from(part, 'hex'));
|
|
54
|
-
const decipher = createDecipheriv('aes-256-cbc', key, iv);
|
|
55
|
-
let decrypted = decipher.update(encrypted, 'hex', 'utf8');
|
|
56
|
-
decrypted += decipher.final('utf8');
|
|
57
|
-
return decrypted;
|
|
58
|
-
},
|
|
59
|
-
ping : ()=>{
|
|
60
|
-
// @TODO ping the database to check connectivity when class is ready to use
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
super(doc_obj)
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export default BeanBagDB_PouchDB
|
package/src/system_schema.js
DELETED
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
export const schema_schema = {
|
|
2
|
-
name: "schema",
|
|
3
|
-
description:"Meta-schema or schema for defining other schemas",
|
|
4
|
-
system_generated:true,
|
|
5
|
-
schema: {
|
|
6
|
-
type: "object",
|
|
7
|
-
additionalProperties: false,
|
|
8
|
-
properties: {
|
|
9
|
-
system_generated:{
|
|
10
|
-
type:"boolean",
|
|
11
|
-
default:false
|
|
12
|
-
},
|
|
13
|
-
name: {
|
|
14
|
-
type: "string",
|
|
15
|
-
minLength: 5,
|
|
16
|
-
maxLength: 50,
|
|
17
|
-
pattern: "^[a-zA-Z][a-zA-Z0-9_]*$",
|
|
18
|
-
},
|
|
19
|
-
description:{
|
|
20
|
-
type:"string",
|
|
21
|
-
minLength:1,
|
|
22
|
-
maxLength:1000
|
|
23
|
-
},
|
|
24
|
-
schema: {
|
|
25
|
-
type: "object",
|
|
26
|
-
additionalProperties: true,
|
|
27
|
-
minProperties: 1,
|
|
28
|
-
maxProperties: 50,
|
|
29
|
-
},
|
|
30
|
-
settings: {
|
|
31
|
-
type: "object",
|
|
32
|
-
additionalProperties: true,
|
|
33
|
-
properties: {
|
|
34
|
-
primary_keys: {
|
|
35
|
-
type: "array",
|
|
36
|
-
default: [],
|
|
37
|
-
items: {
|
|
38
|
-
type: "string",
|
|
39
|
-
},
|
|
40
|
-
maxItems: 10,
|
|
41
|
-
},
|
|
42
|
-
editable_fields: {
|
|
43
|
-
type: "array",
|
|
44
|
-
default: [],
|
|
45
|
-
items: {
|
|
46
|
-
type: "string",
|
|
47
|
-
},
|
|
48
|
-
maxItems: 20,
|
|
49
|
-
},
|
|
50
|
-
encrypted_fields: {
|
|
51
|
-
type: "array",
|
|
52
|
-
default: [],
|
|
53
|
-
items: {
|
|
54
|
-
type: "string",
|
|
55
|
-
},
|
|
56
|
-
maxItems: 10,
|
|
57
|
-
},
|
|
58
|
-
single_record: {
|
|
59
|
-
type: "boolean",
|
|
60
|
-
default: false,
|
|
61
|
-
description:
|
|
62
|
-
"If set, only a single records with this schema will be allowed to insert in the database",
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
required: ["name","description","schema", "settings"],
|
|
68
|
-
},
|
|
69
|
-
settings: {
|
|
70
|
-
primary_key: ["name"],
|
|
71
|
-
editable_fields: ["schema", "settings"],
|
|
72
|
-
},
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
export const system_schemas = {
|
|
76
|
-
logs: {
|
|
77
|
-
system_generated:true,
|
|
78
|
-
description:"Schema for the log doc. Single log doc for the whole DB to log stuff about the DB",
|
|
79
|
-
name: "system_logs",
|
|
80
|
-
schema: {
|
|
81
|
-
type: "object",
|
|
82
|
-
additionalProperties: true,
|
|
83
|
-
properties: {
|
|
84
|
-
logs: {
|
|
85
|
-
type: "array",
|
|
86
|
-
items: {
|
|
87
|
-
type: "object",
|
|
88
|
-
additionalProperties: true,
|
|
89
|
-
},
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
settings: {
|
|
94
|
-
single_record: true
|
|
95
|
-
},
|
|
96
|
-
},
|
|
97
|
-
keys: {
|
|
98
|
-
system_generated:true,
|
|
99
|
-
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",
|
|
100
|
-
name: "system_keys",
|
|
101
|
-
schema: {
|
|
102
|
-
type: "object",
|
|
103
|
-
additionalProperties: true,
|
|
104
|
-
required:["name","value"],
|
|
105
|
-
properties: {
|
|
106
|
-
name: {
|
|
107
|
-
type: "string",
|
|
108
|
-
minLength: 5,
|
|
109
|
-
maxLength: 50,
|
|
110
|
-
pattern: "^[a-zA-Z][a-zA-Z0-9_]*$",
|
|
111
|
-
},
|
|
112
|
-
value: {
|
|
113
|
-
type: "string",
|
|
114
|
-
minLength: 5,
|
|
115
|
-
maxLength: 5000,
|
|
116
|
-
pattern: "^[^\n\r]*$",
|
|
117
|
-
description:"Must be a single line string"
|
|
118
|
-
},
|
|
119
|
-
note: {
|
|
120
|
-
type: "string",
|
|
121
|
-
minLength: 1,
|
|
122
|
-
maxLength: 5000,
|
|
123
|
-
pattern: "^[a-zA-Z][a-zA-Z0-9_]*$",
|
|
124
|
-
},
|
|
125
|
-
},
|
|
126
|
-
},
|
|
127
|
-
settings: {
|
|
128
|
-
primary_keys: ["name"],
|
|
129
|
-
encrypted_fields:["value"]
|
|
130
|
-
},
|
|
131
|
-
},
|
|
132
|
-
settings: {
|
|
133
|
-
system_generated:true,
|
|
134
|
-
description:"The system relies on these settings for proper functioning or enabling optional features.",
|
|
135
|
-
name: "system_settings",
|
|
136
|
-
schema: {
|
|
137
|
-
required:["name","value"],
|
|
138
|
-
type: "object",
|
|
139
|
-
additionalProperties: true,
|
|
140
|
-
properties: {
|
|
141
|
-
name: {
|
|
142
|
-
type: "string",
|
|
143
|
-
minLength: 5,
|
|
144
|
-
maxLength: 250,
|
|
145
|
-
pattern: "^[a-zA-Z][a-zA-Z0-9_]*$",
|
|
146
|
-
},
|
|
147
|
-
value: {
|
|
148
|
-
type: "string",
|
|
149
|
-
minLength: 5,
|
|
150
|
-
maxLength: 5000,
|
|
151
|
-
pattern: "^[^\n\r]*$",
|
|
152
|
-
description:"Must be a single line string"
|
|
153
|
-
},
|
|
154
|
-
user_editable: {
|
|
155
|
-
type: "boolean",
|
|
156
|
-
default: true,
|
|
157
|
-
description:
|
|
158
|
-
"Whether this setting is editable by the user or only by the system",
|
|
159
|
-
},
|
|
160
|
-
},
|
|
161
|
-
},
|
|
162
|
-
settings: {
|
|
163
|
-
primary_keys: ["name"],
|
|
164
|
-
editable_fields: ["value"],
|
|
165
|
-
},
|
|
166
|
-
},
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
// this is not stored in the DB. only for validating the metadata during doc update
|
|
170
|
-
export const editable_metadata_schema = {
|
|
171
|
-
additionalProperties: false,
|
|
172
|
-
properties:{
|
|
173
|
-
tags:{
|
|
174
|
-
type:"array",
|
|
175
|
-
items:{type:"string"},
|
|
176
|
-
default:[],
|
|
177
|
-
maxItems: 40,
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}
|
package/src/utils.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import pkg from '../package.json' assert { type: "json" }; // Import package.json directly
|
|
2
|
-
|
|
3
|
-
// import { readFile } from 'fs/promises';
|
|
4
|
-
// import { fileURLToPath } from 'url';
|
|
5
|
-
// import { dirname, join } from 'path';
|
|
6
|
-
|
|
7
|
-
// // Get the current directory
|
|
8
|
-
// const __filename = fileURLToPath(import.meta.url);
|
|
9
|
-
// const __dirname = dirname(__filename);
|
|
10
|
-
|
|
11
|
-
// // Adjust path to point to the correct location of package.json (move up from /src)
|
|
12
|
-
// const packageJsonPath = join(__dirname, '../package.json'); // Adjust to point to the correct folder
|
|
13
|
-
|
|
14
|
-
// function isNode() {
|
|
15
|
-
// return typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
|
|
16
|
-
// }
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
// // Function to read package.json and get the version
|
|
20
|
-
// async function getPackageVersionNode() {
|
|
21
|
-
// try {
|
|
22
|
-
// const data = await readFile(packageJsonPath, 'utf-8');
|
|
23
|
-
// const packageJson = JSON.parse(data);
|
|
24
|
-
// return packageJson.version;
|
|
25
|
-
// } catch (error) {
|
|
26
|
-
// console.error('Error reading package.json:', error);
|
|
27
|
-
// throw error;
|
|
28
|
-
// }
|
|
29
|
-
// }
|
|
30
|
-
|
|
31
|
-
export async function getPackageVersion() {
|
|
32
|
-
//if (isNode()) {
|
|
33
|
-
// return await getPackageVersionNode(); // Node.js environment
|
|
34
|
-
//} else {
|
|
35
|
-
// return process.env.PACKAGE_VERSION; // Browser environment
|
|
36
|
-
//}
|
|
37
|
-
return pkg.version
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// getPackageVersion().then(version => console.log('Package version:', version));
|
|
41
|
-
import { fileURLToPath } from 'url';
|
|
42
|
-
import { dirname } from 'path';
|
|
43
|
-
|
|
44
|
-
export const __filename = fileURLToPath(import.meta.url);
|
|
45
|
-
export const __dirname = dirname(__filename);
|
package/test/init.test.js
DELETED
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
// to test initialization of the BeanBagDB class. using in memory pouch db for testing to avoid additional setup.
|
|
2
|
-
import PouchDB from 'pouchdb';
|
|
3
|
-
import pouchdbFind from 'pouchdb-find';
|
|
4
|
-
PouchDB.plugin(pouchdbFind)
|
|
5
|
-
import { scryptSync, randomBytes, createCipheriv, createDecipheriv } from 'crypto';
|
|
6
|
-
const db_name = "test_database_24"
|
|
7
|
-
const pdb = new PouchDB(db_name);
|
|
8
|
-
const doc_obj = {
|
|
9
|
-
name: db_name,
|
|
10
|
-
encryption_key: "qwertyuiopaqwsde1254",
|
|
11
|
-
api: {
|
|
12
|
-
insert: async (doc) => {
|
|
13
|
-
const result = await pdb.post(doc);
|
|
14
|
-
return result;
|
|
15
|
-
},
|
|
16
|
-
// delete: ()=>{db1.destroy},
|
|
17
|
-
update: async (doc) => {
|
|
18
|
-
const result = await pdb.put(doc);
|
|
19
|
-
return result;
|
|
20
|
-
},
|
|
21
|
-
search: async (query) => {
|
|
22
|
-
const results = await pdb.find(query);
|
|
23
|
-
return results; // of the form {docs:[],...}
|
|
24
|
-
},
|
|
25
|
-
get: async (id) => {
|
|
26
|
-
const data = await pdb.get(id);
|
|
27
|
-
return data;
|
|
28
|
-
},
|
|
29
|
-
delete: async (id) => {
|
|
30
|
-
const doc = await pdb.get(id);
|
|
31
|
-
const resp = await pdb.remove(doc);
|
|
32
|
-
return resp;
|
|
33
|
-
},
|
|
34
|
-
createIndex: async (filter) => {
|
|
35
|
-
const data = await pdb.createIndex(filter);
|
|
36
|
-
return data;
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
utils: {
|
|
40
|
-
encrypt: (text, encryptionKey) => {
|
|
41
|
-
const key = scryptSync(encryptionKey, "salt", 32); // Derive a 256-bit key
|
|
42
|
-
const iv = randomBytes(16); // Initialization vector
|
|
43
|
-
const cipher = createCipheriv("aes-256-cbc", key, iv);
|
|
44
|
-
let encrypted = cipher.update(text, "utf8", "hex");
|
|
45
|
-
encrypted += cipher.final("hex");
|
|
46
|
-
return iv.toString("hex") + ":" + encrypted; // Prepend the IV for later use
|
|
47
|
-
},
|
|
48
|
-
decrypt: (encryptedText, encryptionKey) => {
|
|
49
|
-
const key = scryptSync(encryptionKey, "salt", 32); // Derive a 256-bit key
|
|
50
|
-
const [iv, encrypted] = encryptedText
|
|
51
|
-
.split(":")
|
|
52
|
-
.map((part) => Buffer.from(part, "hex"));
|
|
53
|
-
const decipher = createDecipheriv("aes-256-cbc", key, iv);
|
|
54
|
-
let decrypted = decipher.update(encrypted, "hex", "utf8");
|
|
55
|
-
decrypted += decipher.final("utf8");
|
|
56
|
-
return decrypted;
|
|
57
|
-
},
|
|
58
|
-
ping: () => {
|
|
59
|
-
// @TODO ping the database to check connectivity when class is ready to use
|
|
60
|
-
},
|
|
61
|
-
},
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
let the_correct_object = {};
|
|
65
|
-
|
|
66
|
-
import { throws, strictEqual } from "assert";
|
|
67
|
-
|
|
68
|
-
import BeanBagDB from '../src/beanbagdb.js';
|
|
69
|
-
/**
|
|
70
|
-
* Initial setup
|
|
71
|
-
* database is the global var where the beanbag class is initialized
|
|
72
|
-
*/
|
|
73
|
-
const test_set1 = [
|
|
74
|
-
["name", "sample"],
|
|
75
|
-
["encryption_key", "sample_key"],
|
|
76
|
-
["utils", {}],
|
|
77
|
-
["api", {}],
|
|
78
|
-
];
|
|
79
|
-
const test_obj = { name: "bla", encryption_key: "1234567890opuityerqwas" };
|
|
80
|
-
const full_util = {util: { encrypt: () => {}, decrypt: () => {}, ping: () => {} },}
|
|
81
|
-
const full_api = {api: { update: () => {}, delete: () => {}, get: () => {}, search: () => {}, createIndex: () => {}}}
|
|
82
|
-
const test_set_api = [
|
|
83
|
-
[
|
|
84
|
-
"api.insert missing",
|
|
85
|
-
{
|
|
86
|
-
...test_obj,
|
|
87
|
-
...full_util,
|
|
88
|
-
api: {update: () => {}, delete: () => {}, get: () => {}, search: () => {}, createIndex: () => {}},
|
|
89
|
-
},
|
|
90
|
-
],
|
|
91
|
-
[
|
|
92
|
-
"api.update missing",
|
|
93
|
-
{
|
|
94
|
-
...test_obj,
|
|
95
|
-
...full_util,
|
|
96
|
-
api: {insert: () => {}, delete: () => {}, get: () => {},search: () => {},createIndex: () => {}},
|
|
97
|
-
},
|
|
98
|
-
],
|
|
99
|
-
[
|
|
100
|
-
"api.delete missing",
|
|
101
|
-
{
|
|
102
|
-
...test_obj,
|
|
103
|
-
...full_util,
|
|
104
|
-
api: { insert: () => {}, update: () => {}, get: () => {}, search: () => {}, createIndex: () => {}},
|
|
105
|
-
},
|
|
106
|
-
],
|
|
107
|
-
[
|
|
108
|
-
"api.get missing",
|
|
109
|
-
{
|
|
110
|
-
...test_obj,
|
|
111
|
-
...full_util,
|
|
112
|
-
api: { insert: () => {}, update: () => {}, delete: () => {}, search: () => {}, createIndex: () => {}}
|
|
113
|
-
},
|
|
114
|
-
],
|
|
115
|
-
[
|
|
116
|
-
"api.search missing",
|
|
117
|
-
{
|
|
118
|
-
...test_obj,
|
|
119
|
-
...full_util,
|
|
120
|
-
api: { insert: () => {}, update: () => {}, delete: () => {}, get: () => {}, createIndex: () => {}}
|
|
121
|
-
},
|
|
122
|
-
],
|
|
123
|
-
[
|
|
124
|
-
"api.createIndex missing",
|
|
125
|
-
{
|
|
126
|
-
...test_obj,
|
|
127
|
-
...full_util,
|
|
128
|
-
api: { insert: () => {}, update: () => {}, delete: () => {}, get: () => {}, search: () => {}},
|
|
129
|
-
},
|
|
130
|
-
],
|
|
131
|
-
[
|
|
132
|
-
"util.encrypt missing",
|
|
133
|
-
{ ...test_obj, ...full_api, util: { decrypt: () => {}, ping: () => {} } },
|
|
134
|
-
],
|
|
135
|
-
[
|
|
136
|
-
"util.decrypt missing",
|
|
137
|
-
{ ...test_obj, ...full_api, util: { encrypt: () => {}, ping: () => {} } },
|
|
138
|
-
],
|
|
139
|
-
[
|
|
140
|
-
"util.ping missing",
|
|
141
|
-
{
|
|
142
|
-
...test_obj,
|
|
143
|
-
...full_api,
|
|
144
|
-
util: { encrypt: () => {}, decrypt: () => {} },
|
|
145
|
-
},
|
|
146
|
-
],
|
|
147
|
-
];
|
|
148
|
-
|
|
149
|
-
let database;
|
|
150
|
-
|
|
151
|
-
describe("Tests initialization of the BeanBagDB class without no init object", async () => {
|
|
152
|
-
it("Throws error", () => {
|
|
153
|
-
throws(() => {
|
|
154
|
-
database = new BeanBagDB();
|
|
155
|
-
}, Error);
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
describe("Tests initialization of the BeanBagDB class with incomplete init object", async () => {
|
|
160
|
-
/*
|
|
161
|
-
* Proper object : {name,encryption_key,api:{insert,updated,delete,search,get,createIndex},utils:{encrypt,decrypt,ping}}
|
|
162
|
-
*/
|
|
163
|
-
it("Blank object throw error", () => {
|
|
164
|
-
throws(() => {
|
|
165
|
-
database = new BeanBagDB({});
|
|
166
|
-
}, Error);
|
|
167
|
-
});
|
|
168
|
-
it("some invalid field throws error", () => {
|
|
169
|
-
throws(() => {
|
|
170
|
-
database = new BeanBagDB({ dbname: "sample" });
|
|
171
|
-
}, Error);
|
|
172
|
-
});
|
|
173
|
-
test_set1.forEach((item) => {
|
|
174
|
-
it(`only ${item[0]} throws error`, () => {
|
|
175
|
-
throws(() => {
|
|
176
|
-
let key = item[0];
|
|
177
|
-
database = new BeanBagDB({ key: item[1] });
|
|
178
|
-
}, Error);
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
test_set_api.forEach((item) => {
|
|
182
|
-
it(`${item[0]} throws error`, () => {
|
|
183
|
-
throws(() => {
|
|
184
|
-
let obj = { ...item[1] };
|
|
185
|
-
database = new BeanBagDB(obj);
|
|
186
|
-
}, Error);
|
|
187
|
-
});
|
|
188
|
-
});
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
describe("Successful database class init", async () => {
|
|
192
|
-
it("global database variable not yet initialized", () => {
|
|
193
|
-
strictEqual(
|
|
194
|
-
database instanceof BeanBagDB,
|
|
195
|
-
false,
|
|
196
|
-
"The variable is not yet initialized"
|
|
197
|
-
);
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
it("DB init successful", () => {
|
|
201
|
-
database = new BeanBagDB(doc_obj);
|
|
202
|
-
strictEqual(
|
|
203
|
-
database instanceof BeanBagDB,
|
|
204
|
-
true,
|
|
205
|
-
"The variable is initialized successfully"
|
|
206
|
-
);
|
|
207
|
-
});
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* process is : create a new obj with all required inputs, run ready() , then initialize_db , then ready to perform operations
|
|
212
|
-
*
|
|
213
|
-
* to test:
|
|
214
|
-
* - no object
|
|
215
|
-
* - incomplete objects and inner objects
|
|
216
|
-
* - good example
|
|
217
|
-
*
|
|
218
|
-
* initialized by ready not called ,
|
|
219
|
-
*/
|
package/test/operations.test.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
// to test database operations. assuming the class is initialized successfully
|
package/test/test1.js
DELETED
|
@@ -1,157 +0,0 @@
|
|
|
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
|
-
// })();
|