firestorm-db
Advanced tools
Comparing version 1.5.0 to 1.6.0
83
index.js
@@ -1,2 +0,6 @@ | ||
const { default: axios } = require("axios") | ||
try { | ||
if(typeof process === 'object') { | ||
var axios = require("axios").default | ||
} | ||
} catch(_error) {} | ||
@@ -94,2 +98,14 @@ /** | ||
/** | ||
* Send get request and extract data from ir | ||
* @param {Object} data Body data | ||
* @returns {Promise<Any>} data out | ||
*/ | ||
__get_request(data) { | ||
const request = typeof process === 'object' ? axios.get(readAddress(), { | ||
data: data | ||
}) : axios.post(readAddress(), data) | ||
return this.__extract_data(request) | ||
} | ||
/** | ||
* Get an element from the collection | ||
@@ -100,7 +116,7 @@ * @param {String|Number} id The entry ID | ||
get(id) { | ||
return this.__add_methods(this.__extract_data(axios.get(readAddress(), { data: { | ||
return this.__add_methods(this.__get_request({ | ||
"collection": this.collectionName, | ||
"command": "get", | ||
"id": id | ||
}}))) | ||
})) | ||
} | ||
@@ -118,3 +134,3 @@ | ||
searchOptions.forEach(searchOption => { | ||
if(!searchOption.field || !searchOption.criteria || !searchOption.value) | ||
if(searchOption.field === undefined || searchOption.criteria === undefined || searchOption.value === undefined) | ||
return Promise.reject(new Error('Missing fields in searchOptions array')) | ||
@@ -132,9 +148,7 @@ | ||
return new Promise((resolve, reject) => { | ||
this.__extract_data(axios.get(readAddress(), { | ||
data: { | ||
"collection": this.collectionName, | ||
"command": "search", | ||
"search": searchOptions | ||
} | ||
})).then(res => { | ||
this.__get_request({ | ||
"collection": this.collectionName, | ||
"command": "search", | ||
"search": searchOptions | ||
}).then(res => { | ||
const arr = [] | ||
@@ -164,9 +178,7 @@ | ||
return new Promise((resolve, reject) => { | ||
this.__extract_data(axios.get(readAddress(), { | ||
data: { | ||
"collection": this.collectionName, | ||
"command": "searchKeys", | ||
"search": keys | ||
} | ||
})).then(res => { | ||
this.__get_request({ | ||
"collection": this.collectionName, | ||
"command": "searchKeys", | ||
"search": keys | ||
}).then(res => { | ||
const arr = [] | ||
@@ -191,8 +203,6 @@ Object.keys(res).forEach(contribID => { | ||
return new Promise((resolve, reject) => { | ||
this.__extract_data(axios.get(readAddress(), { | ||
data: { | ||
"collection": this.collectionName, | ||
"command": "read_raw" | ||
} | ||
})) | ||
this.__get_request({ | ||
"collection": this.collectionName, | ||
"command": "read_raw" | ||
}) | ||
.then(data => { | ||
@@ -217,10 +227,7 @@ Object.keys(data).forEach(key => { | ||
return new Promise((resolve, reject) => { | ||
this.__extract_data(axios.get(readAddress(), { | ||
data: { | ||
'collection': this.collectionName, | ||
'command': 'select', | ||
'select': selectOption | ||
} | ||
})) | ||
.then(data => { | ||
this.__get_request({ | ||
'collection': this.collectionName, | ||
'command': 'select', | ||
'select': selectOption | ||
}).then(data => { | ||
Object.keys(data).forEach(key => { | ||
@@ -375,7 +382,7 @@ data[key][ID_FIELD_NAME] = key | ||
const data = this.__write_data('editFieldBulk', objArray, undefined) | ||
return this.__extract_data(axios.post(writeAddress()), data) | ||
return this.__extract_data(axios.post(writeAddress(), data)) | ||
} | ||
} | ||
module.exports = { | ||
const firestorm = { | ||
/** | ||
@@ -415,2 +422,10 @@ * @param {String} newValue The new address value | ||
ID_FIELD: ID_FIELD_NAME | ||
} | ||
try { | ||
if(typeof process === 'object') { | ||
module.exports = firestorm | ||
} | ||
} catch (_error) { | ||
// normal browser | ||
} |
{ | ||
"name": "firestorm-db", | ||
"version": "1.5.0", | ||
"version": "1.6.0", | ||
"description": "Self hosted Firestore-like database with API endpoints based on micro bulk operations", | ||
@@ -8,3 +8,3 @@ "main": "index.js", | ||
"php_start": "node tests/php_setup.js", | ||
"test": "mocha tests/**/*.spec.js", | ||
"test": "./node_modules/.bin/mocha tests/**/*.spec.js", | ||
"php_stop": "sh tests/php_server_kill.sh", | ||
@@ -11,0 +11,0 @@ "full": "npm run php_start && npm run test ; npm run php_stop", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23561
369