Permalink
Browse files

Merge pull request #23 from apb2006/dev

Dev
  • Loading branch information...
2 parents 1a87de5 + bbabb11 commit a1bc3d90d7b255d9c2bb0151f9c1014a6414f493 @apb2006 committed on GitHub Mar 23, 2017
Showing with 103 additions and 53 deletions.
  1. +28 −17 LICENSE
  2. +1 −1 README.md
  3. +5 −0 changelog.md
  4. +4 −17 docs/commands.md
  5. +1 −1 examples/issue21.js
  6. +42 −0 examples/issue22.js
  7. +16 −11 index.js
  8. +6 −6 package.json
View
@@ -1,20 +1,31 @@
-Copyright (c) 2011-2012 Andy Bunce
+Copyright (c) 2011-2017 Andy Bunce
+All rights reserved.
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
+The BSD 3-Clause License
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+3. Neither the name of the copyright holders nor the names of its
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
View
@@ -21,7 +21,7 @@ To install with npm:
$ mkdir myproject
cd myproject
$ npm install basex
- basex@0.8.0 ./node_modules/basex
+ basex@0.9.0 ./node_modules/basex
```
Once BaseX is installed and the BaseX server is running, test it.
View
@@ -1,3 +1,8 @@
+## v0.9.0 - 2017-03-23
+- session object now emits socketError events - see #9 #21
+- min node version set to 4.0
+- dependancies updated
+
## v0.8.0 - 2017-03-14
- Remove obsolete event watch interface.
- Fix #21 query.execute with error.
View
@@ -31,6 +31,9 @@ The default values are:
username (default="admin")
password (default= "admin")
+Since version 0.8.1 the `session` object emits `socketError` events on socket errors.
+This allows an application to react to events such as the server doing down.(See `examples/issue22.js`)
+
# Session commands
##execute
@@ -85,23 +88,7 @@ Replaces a document with the specified input stream.
````
Stores raw data at the specified path.
-##watch
-````
- session.watch(name,notification,callback)
-````
-Request notifications for event with `name`. The function `notification` is called
-each time an event with the name is received. The signature is `notification(name,data)`.
-````
-function watchCallback(name,msg){
-console.log("watch update-----> ",msg)
-};
-session1.watch("testevent",watchCallback, log.print);
-````
-##unwatch
-````
- session.unwatch(name,callback)
-````
-Unwatches the specified event.
+
##info
session.info(callback)
View
@@ -3,7 +3,7 @@
*/
const basex = require("../index");
var session = new basex.Session()
-basex.debug_mode = false;
+basex.debug_mode = true;
function performQuery(q_str) {
return new Promise(rs => {
var q = session.query(q_str)
View
@@ -0,0 +1,42 @@
+/*
+ * socket errors #22
+ */
+const basex = require("../index");
+
+basex.debug_mode = false;
+var session;
+
+
+function socketError(e){
+ console.log("socket trouble detected..",e.code);
+ if (e.code == 'ECONNREFUSED') {
+ console.error('connection refused. Check BaseX server is running.');
+ } else if(e.code == 'ECONNRESET' || e.code == 'EPIPE'){
+ console.log("Restarting client in 10 seconds");
+ setTimeout(work, 10000); // 10 seconds pass..
+ } else {
+ console.error("SOCKET ERROR: ", e.code,":", e);
+ }
+};
+function work(){
+ console.log("New session");
+ session = new basex.Session();
+ session.on("socketError",socketError);
+ // poll server time every second
+ setInterval(serverdateTime,1000);
+};
+
+
+function serverdateTime() {
+ var query = 'fn:current-dateTime()';
+ var q = session.query(query)
+ q.execute((e, r) => { console.log("Result: ", r.result, "; Error:", e);});
+};
+
+
+
+work();
+
+
+
+
View
@@ -61,8 +61,7 @@ var Session = function(host, port, username, password) {
this.buffer = "";
this.q_pending = new Queue(); // holds commands to send
this.q_sent = new Queue(); // holds commands sent
- // event stuff
- this.event = null;
+
// initial parser for auth
/**
* Description
@@ -154,15 +153,14 @@ var Session = function(host, port, username, password) {
//console.dir(self.current_command);
}
};
-
- this.stream.on("error", socketError);
-
+
+ this.stream.on("error", socketError.bind(this));
+ // this.stream.on('error', this.emit.bind(this, 'socketError'));
this.stream.on("close", function() {
if (exports.debug_mode) {
console.log(self.tag + ": stream closed");
}
- if (self.event) self.event.close()
-
+
if (self.closefn) {
self.closefn();
self.closefn = null;
@@ -413,18 +411,25 @@ var Session = function(host, port, username, password) {
};
/**
- * Description
+ * react to socket errors.
+ * @TODO research error meanings
* @method socketError
* @param {} e
* @return
*/
function socketError(e) {
if (e.code == 'ECONNREFUSED') {
- console.log('ECONNREFUSED: connection refused. Check BaseX server is running.');
+ console.error('ECONNREFUSED: connection refused. Check BaseX server is running.');
+ }else if (e.code == 'ECONNRESET') {
+ console.error('ECONNRESET: reset.',this.tag);
+ }else if ( e.code == 'EPIPE') {
+ console.error('EPIPE');
} else {
- console.log("SOCKET ERROR: ", e);
- }
+ console.error("SOCKET ERROR: ", e);
+ };
+ this.emit("socketError",e)
}
+
/**
* hash str using md5
* @method md5
View
@@ -1,14 +1,14 @@
{
"name": "basex",
- "version": "0.8.0",
+ "version": "0.9.0",
"description": "A BaseX (XML database) client library",
"keywords":
[
"xml",
"xquery",
"xslt",
- "search",
- "database"
+ "database",
+ "basex"
],
"author": "Andy Bunce ",
@@ -26,7 +26,7 @@
"dependencies":
{
- "combined-stream": "0.0.4"
+ "combined-stream": "1.0.3"
},
"devDependencies":
@@ -38,8 +38,8 @@
"engines":
{
- "node": ">=0.6"
+ "node": ">=4.0"
},
- "license": "BSD"
+ "license": "BSD-3-Clause"
}

0 comments on commit a1bc3d9

Please sign in to comment.