on master help sign in
add comments to js driver and add some basic websocket/js documentation

resolves #77

commit02b60f1f0003cef3b96b00d179fc31bdd58e53b2 authorAgentM <agentm@themactionfaction.com> dateWed 15 Feb 2017, 19:40 (10 years ago) parentc67c55f
2 files changed+48
docs/javascript_driver.markdown+21 src/bin/ProjectM36/Server/WebSocket/project-m36.js+27
docs/javascript_driver.markdownnew file+21
@@ -0,0 +1,21 @@
1+# Project:M36 JavaScript Driver
2+
3+## Introduction
4+
5+ The JavaScript database driver for Project:M36 is a fully-featured database driver for the Project:M36 Relational Algebra Engine DBMS. The driver's only dependency is a working websockets implementation which is provided by virtually any modern web browser and node.js. The API is callback-based.
6+
7+ ## Usage
8+
9+1. [Download the driver](/src/bin/ProjectM36/Websocket/project-m36.js).
10+1. Connect to the websocket server with a ```new ProjectM36Connection(..)``` including the asynchronous callback functions.
11+1. When the ```openCallback``` is called, the database is ready to execute TutorialD sing the ```executeTutorialD()``` function.
12+1. Implement ```statusCallback``` to update your user interface for expected and asynchronous event handling.
13+
14+## Example
15+
16+A fully-functioning interactive websocket client is available:
17+
18+* [websocket-client.html](/src/bin/ProjectM36/Server/WebSocket/websocket-client.html)
19+* [websocket-client.js](/src/bin/ProjectM36/Server/WebSocket/websocket-client.js)
20+
21+This example also powers [try.project-m36.io](https://try.project-m36.io).
src/bin/ProjectM36/Server/WebSocket/project-m36.js+27
@@ -1,3 +1,15 @@
1+/**
2+* Returns a connection to a Project:M36 database. The connection created relies on websockets and should therefore function from any modern web browser or node server. This API is asynchronous and callback-based.
3+* @param {string} protocol - Choose from "ws://" and "wss://". "wss" is the SSL-wrapped websockets protocol and should therefore be preferred.
4+* @param {string} host - The IP address or name of the host of the database.
5+* @param {string} path - The websocket path where the websocket server is bound. Unless the project-m36-websocket-server is proxied, this is ignored by the server.
6+* @param {string} dbname - The name of the remote database.
7+* @param {openCallback} openCallback - A function to call when the connection is successfully open and ready for queries.
8+* @param {errorCallback} errorCallback - A function called if the connection process encounters an error. This is not called for errors in the queries.
9+* @param {statusCallback} statusCallback - A function called with synchronous and asynchronous status updates such as query errors and query results.
10+* @param {promptCallback} promptCallback - A function called whenever prompt information such as the current schema name and current branch name (if any).
11+* @param {closeCallback} closeCallback - A function called once the connection is closed.
12+*/
113var ProjectM36Connection = function (protocol, host, port, path, dbname, openCallback, errorCallback, statusCallback, promptCallback, closeCallback) {
214 this.protocol = protocol;
315 this.host = host;
@@ -35,6 +47,13 @@ var ProjectM36Connection = function (protocol, host, port, path, dbname, openCal
3547 this.socket = socket;
3648}
3749
50+/**
51+* The argument returned as part of the 'statusCallback'. Typically, only one of the three status types is populated. These status updates are groups together so that the callback can feed into a user interface update function.
52+* @callback statusCallback
53+* @param {Object} relationResult - The status update containing a relation or null.
54+* @param {Object} acknowledgementresult - The status update containing an acknowledgement that the query was executed or null.
55+* @param {Object} errorResult - The status update containing the error information or null.
56+*/
3857var ProjectM36Status = function (relationResult, acknowledgementResult, errorResult)
3958{
4059 this.relation = relationResult;
@@ -84,11 +103,19 @@ ProjectM36Connection.prototype.handleResponse = function(message)
84103 }
85104}
86105
106+/**
107+* Executes a TutorialD string.
108+* @param {string} tutd - The TutorialD string.
109+*/
87110ProjectM36Connection.prototype.executeTutorialD = function(tutd)
88111{
89112 this.socket.send("executetutd:" + tutd);
90113}
91114
115+/**
116+* A utitily function which creates and returns a table element representing the relation.
117+* @param {object} - The relation returned from executing a relational expression.
118+*/
92119ProjectM36Connection.prototype.generateRelation = function(relation)
93120{
94121 var table = document.createElement("table");