Commit 86851fbe authored by Tristan Cavelier's avatar Tristan Cavelier

Great Jio improve

Redesigned to use put,get,remove and allDocs instead of
{save,load,remove}Document and getDocumentList.
These methods are similar to PouchDB methods.
Error objects are similar to jQuery and CouchDB.
Error status are unique.
Storage design difficulty decreased.
parent 50d6fc2f
......@@ -21,10 +21,11 @@ module.exports = function(grunt) {
'<file_strip_banner:../../src/<%= pkg.name %>/storages/storage.js>',
'<file_strip_banner:../../src/<%= pkg.name %>/storages/storageHandler.js>',
'<file_strip_banner:../../src/<%= pkg.name %>/commands/command.js>',
'<file_strip_banner:../../src/<%= pkg.name %>/commands/getDocumentList.js>',
'<file_strip_banner:../../src/<%= pkg.name %>/commands/loadDocument.js>',
'<file_strip_banner:../../src/<%= pkg.name %>/commands/removeDocument.js>',
'<file_strip_banner:../../src/<%= pkg.name %>/commands/saveDocument.js>',
'<file_strip_banner:../../src/<%= pkg.name %>/commands/allDocsCommand.js>',
'<file_strip_banner:../../src/<%= pkg.name %>/commands/getCommand.js>',
'<file_strip_banner:../../src/<%= pkg.name %>/commands/removeCommand.js>',
'<file_strip_banner:../../src/<%= pkg.name %>/commands/putCommand.js>',
'<file_strip_banner:../../src/<%= pkg.name %>/commands/postCommand.js>',
'<file_strip_banner:../../src/<%= pkg.name %>/jobs/status/jobStatus.js>',
'<file_strip_banner:../../src/<%= pkg.name %>/jobs/status/doneStatus.js>',
'<file_strip_banner:../../src/<%= pkg.name %>/jobs/status/failStatus.js>',
......
/*! JIO - v0.1.0 - 2012-08-01
/*! JIO - v0.1.0 - 2012-08-14
* Copyright (c) 2012 Nexedi; Licensed */
var jio = (function () {
......@@ -90,12 +90,13 @@ var storage = function(spec, my) {
* @param {object} command The command
*/
that.execute = function(command) {
that.validate(command);
that.success = command.success;
that.error = command.error;
that.retry = command.retry;
that.end = command.end;
command.executeOn(that);
if (that.validate(command)) {
command.executeOn(that);
}
};
/**
......@@ -107,12 +108,15 @@ var storage = function(spec, my) {
return true;
};
that.validate = function(command) {
that.validate = function () {
var mess = that.validateState();
if (mess) {
throw invalidStorage({storage:that,message:mess});
that.error({status:0,statusText:'Invalid Storage',
error:'invalid_storage',
message:mess,reason:mess});
return false;
}
command.validate(that);
return true;
};
/**
......@@ -125,7 +129,8 @@ var storage = function(spec, my) {
};
that.saveDocument = function(command) {
throw invalidStorage({storage:that,message:'Unknown storage.'});
that.error({status:0,statusText:'Unknown storage',
error:'unknown_storage',message:'Unknown Storage'});
};
that.loadDocument = function(command) {
that.saveDocument();
......@@ -157,21 +162,32 @@ var storage = function(spec, my) {
var storageHandler = function(spec, my) {
spec = spec || {};
my = my || {};
var that = storage( spec, my );
var that = storage( spec, my ), priv = {};
that.newCommand = function (method, spec) {
priv.newCommand = function (method, spec) {
var o = spec || {};
o.label = method;
return command (o, my);
};
that.newStorage = function (spec) {
var o = spec || {};
return jioNamespace.storage (o, my);
};
that.addJob = function (storage,command) {
my.jobManager.addJob ( job({storage:storage, command:command}, my) );
that.addJob = function (method,storage_spec,doc,option,success,error) {
var command_opt = {
options: option,
callbacks:{success:success,error:error}
};
if (doc) {
if (method === 'get') {
command_opt.docid = doc;
} else {
command_opt.doc = doc;
}
}
my.jobManager.addJob (
job({
storage:jioNamespace.storage(storage_spec||{}),
command:priv.newCommand(method,command_opt)
}, my)
);
};
return that;
......@@ -183,10 +199,11 @@ var command = function(spec, my) {
my = my || {};
// Attributes //
var priv = {};
priv.commandlist = {'saveDocument':saveDocument,
'loadDocument':loadDocument,
'removeDocument':removeDocument,
'getDocumentList':getDocumentList};
priv.commandlist = {'post':postCommand,
'put':putCommand,
'get':getCommand,
'remove':removeCommand,
'allDocs':allDocsCommand};
// creates the good command thanks to his label
if (spec.label && priv.commandlist[spec.label]) {
priv.label = spec.label;
......@@ -194,14 +211,18 @@ var command = function(spec, my) {
return priv.commandlist[priv.label](spec, my);
}
priv.path = spec.path || '';
priv.tried = 0;
priv.option = spec.option || {};
priv.success = priv.option.success || function (){};
priv.error = priv.option.error || function (){};
priv.doc = spec.doc || {};
priv.docid = spec.docid || '';
priv.option = spec.options || {};
priv.callbacks = spec.callbacks || {};
priv.success = priv.callbacks.success || function (){};
priv.error = priv.callbacks.error || function (){};
priv.retry = function() {
that.error({status:13,statusText:'Fail Retry',
message:'Impossible to retry.'});
that.error({
status:13,statusText:'Fail Retry',error:'fail_retry',
message:'Impossible to retry.',reason:'Impossible to retry.'
});
};
priv.end = function() {};
priv.on_going = false;
......@@ -216,8 +237,7 @@ var command = function(spec, my) {
that.serialized = function() {
return {label:that.getLabel(),
tried:priv.tried,
max_retry:priv.max_retry,
path:priv.path,
doc:that.cloneDoc(),
option:that.cloneOption()};
};
......@@ -230,13 +250,21 @@ var command = function(spec, my) {
return 'command';
};
that.getDocId = function () {
return priv.docid || priv.doc._id;
};
that.getDocContent = function () {
return priv.doc.content;
};
/**
* Returns the path of the command.
* @method getPath
* @return {string} The path of the command.
* Returns an information about the document.
* @method getDocInfo
* @param {string} infoname The info name.
* @return The info value.
*/
that.getPath = function() {
return priv.path;
that.getDocInfo = function (infoname) {
return priv.doc[infoname];
};
/**
......@@ -245,38 +273,56 @@ var command = function(spec, my) {
* @param {string} optionname The option name.
* @return The option value.
*/
that.getOption = function(optionname) {
that.getOption = function (optionname) {
return priv.option[optionname];
};
/**
* Validates the storage.
* Override this function.
* @param {object} handler The storage handler
* @param {object} storage The storage.
*/
that.validate = function(handler) {
that.validateState();
that.validate = function (storage) {
if (!that.validateState()) { return false; }
return storage.validate();
};
/*
* Extend this function
*/
that.validateState = function() {
if (typeof priv.doc !== 'object') {
that.error({
status:20,
statusText:'Document_Id Required',
error:'document_id_required',
message:'No document id.',
reason:'no document id'
});
return false;
}
return true;
};
that.canBeRetried = function () {
return (priv.option.max_retry === 0 ||
return (typeof priv.option.max_retry === 'undefined' ||
priv.option.max_retry === 0 ||
priv.tried < priv.option.max_retry);
};
that.getTried = function() {
return priv.tried;
};
/**
* Delegate actual excecution the storage handler.
* @param {object} handler The storage handler.
* Delegate actual excecution the storage.
* @param {object} storage The storage.
*/
that.execute = function(handler) {
that.execute = function(storage) {
if (!priv.on_going) {
that.validate(handler);
priv.tried ++;
priv.on_going = true;
handler.execute(that);
if (that.validate (storage)) {
priv.tried ++;
priv.on_going = true;
storage.execute (that);
}
}
};
......@@ -288,16 +334,6 @@ var command = function(spec, my) {
*/
that.executeOn = function(storage) {};
/*
* Do not override.
* Override `validate()' instead
*/
that.validateState = function() {
if (priv.path === '') {
throw invalidCommandState({command:that,message:'Path is empty'});
}
};
that.success = function(return_value) {
priv.on_going = false;
priv.success (return_value);
......@@ -378,135 +414,163 @@ var command = function(spec, my) {
return o;
};
/**
* Clones the document and returns the clone version.
* @method cloneDoc
* @return {object} The clone of the document.
*/
that.cloneDoc = function () {
if (priv.docid) {
return priv.docid;
}
var k, o = {};
for (k in priv.doc) {
o[k] = priv.doc[k];
}
return o;
};
return that;
};
var getDocumentList = function(spec, my) {
var allDocsCommand = function(spec, my) {
var that = command(spec, my);
spec = spec || {};
my = my || {};
// Attributes //
// Methods //
that.getLabel = function() {
return 'getDocumentList';
return 'allDocs';
};
that.executeOn = function(storage) {
storage.getDocumentList(that);
storage.allDocs (that);
};
that.canBeRestored = function() {
return false;
};
var super_success = that.success;
that.success = function (res) {
var i;
if (res) {
for (i = 0; i < res.length; i+= 1) {
if (typeof res[i].last_modified !== 'number') {
res[i].last_modified =
new Date(res[i].last_modified).getTime();
}
if (typeof res[i].creation_date !== 'number') {
res[i].creation_date =
new Date(res[i].creation_date).getTime();
}
}
}
super_success(res);
};
return that;
};
var loadDocument = function(spec, my) {
var getCommand = function(spec, my) {
var that = command(spec, my);
spec = spec || {};
my = my || {};
// Attributes //
// Methods //
that.getLabel = function() {
return 'loadDocument';
return 'get';
};
that.validateState = function() {
if (!that.getDocId()) {
that.error({
status:20,statusText:'Document Id Required',
error:'document_id_required',
message:'No document id.',reason:'no document id'
});
return false;
}
return true;
};
that.executeOn = function(storage) {
storage.loadDocument(that);
storage.get (that);
};
that.canBeRestored = function() {
return false;
};
var super_success = that.success;
that.success = function (res) {
if (res) {
if (typeof res.last_modified !== 'number') {
res.last_modified=new Date(res.last_modified).getTime();
}
if (typeof res.creation_date !== 'number') {
res.creation_date=new Date(res.creation_date).getTime();
}
}
super_success(res);
};
return that;
};
var removeDocument = function(spec, my) {
var removeCommand = function(spec, my) {
var that = command(spec, my);
spec = spec || {};
my = my || {};
// Attributes //
// Methods //
that.getLabel = function() {
return 'removeDocument';
return 'remove';
};
that.executeOn = function(storage) {
storage.removeDocument(that);
storage.remove (that);
};
return that;
};
var saveDocument = function(spec, my) {
var putCommand = function(spec, my) {
var that = command(spec, my);
spec = spec || {};
my = my || {};
// Attributes //
var priv = {};
priv.content = spec.content;
// Methods //
that.getLabel = function() {
return 'saveDocument';
};
that.getContent = function() {
return priv.content;
return 'put';
};
/**
* Validates the storage handler.
* @param {object} handler The storage handler
*/
var super_validate = that.validate;
that.validate = function(handler) {
if (typeof priv.content !== 'string') {
throw invalidCommandState({command:that,message:'No data to save'});
var super_validateState = that.validateState;
that.validate = function () {
if (typeof that.getDocInfo('content') !== 'string') {
that.error({
status:21,statusText:'Content Required',
error:'content_required',
message:'No data to put.',reason:'no data to put'
});
return false;
}
super_validate(handler);
return super_validateState();
};
that.executeOn = function(storage) {
storage.saveDocument(that);
storage.put (that);
};
var super_serialized = that.serialized;
that.serialized = function() {
var o = super_serialized();
o.content = priv.content;
return o;
return that;
};
var postCommand = function(spec, my) {
var that = command(spec, my);
spec = spec || {};
my = my || {};
// Attributes //
var priv = {};
// Methods //
that.getLabel = function() {
return 'post';
};
/**
* Validates the storage handler.
* @param {object} handler The storage handler
*/
var super_validateState = that.validateState;
that.validate = function () {
if (typeof that.getDocInfo('content') !== 'string') {
that.error({
status:21,statusText:'Content Required',
error:'content_required',
message:'No data to put.',reason:'no data to put'
});
return false;
}
return super_validateState();
};
that.executeOn = function(storage) {
storage.put (that);
};
return that;
......@@ -775,7 +839,7 @@ var job = function(spec, my) {
* @return {boolean} true if ready, else false.
*/
that.isReady = function() {
if (that.getCommand().getTried() === 0) {
if (priv.command.getTried() === 0) {
return priv.status.canStart();
} else {
return priv.status.canRestart();
......@@ -842,8 +906,9 @@ var job = function(spec, my) {
that.eliminated = function () {
priv.command.error ({
status:10,statusText:'Stoped',
message:'This job has been stoped by another one.'});
status:10,statusText:'Stopped',error:'stopped',
message:'This job has been stoped by another one.',
reason:this.message});
};
that.notAccepted = function () {
......@@ -851,8 +916,9 @@ var job = function(spec, my) {
priv.status = failStatus();
my.jobManager.terminateJob (that);
});
priv.command.error ({status:11,statusText:'Not Accepted',
message:'This job is already running.'});
priv.command.error ({
status:11,statusText:'Not Accepted',error:'not_accepted',
message:'This job is already running.',reason:this.message});
};
/**
......@@ -861,13 +927,19 @@ var job = function(spec, my) {
* @param {object} job The other job.
*/
that.update = function(job) {
priv.command.error ({status:12,statusText:'Replaced',
message:'Job has been replaced by another one.'});
priv.date = job.getDate();
priv.command.error ({
status:12,statusText:'Replaced',error:'replaced',
message:'Job has been replaced by another one.',
reason:'job has been replaced by another one'});
priv.date = new Date(job.getDate().getTime());
priv.command = job.getCommand();
priv.status = job.getStatus();
};
/**
* Executes this job.
* @method execute
*/
that.execute = function() {
if (!that.getCommand().canBeRetried()) {
throw tooMuchTriesJobException(
......@@ -1192,7 +1264,7 @@ var jobManager = (function(spec, my) {
priv.restoreOldJioId = function(id) {
var jio_date;
jio_date = LocalOrCookieStorage.getItem('jio/id/'+id)||0;
if (jio_date < (Date.now() - 10000)) { // 10 sec
if (new Date(jio_date).getTime() < (Date.now() - 10000)) { // 10 sec
priv.restoreOldJobFromJioId(id);
priv.removeOldJioId(id);
priv.removeJobArrayFromJioId(id);
......@@ -1292,8 +1364,8 @@ var jobManager = (function(spec, my) {
* @param {object} job The new job.
*/
that.addJob = function(job) {
var result_a = that.validateJobAccordingToJobList (priv.job_array,job);
priv.appendJob (job,result_a);
var result_array = that.validateJobAccordingToJobList (priv.job_array,job);
priv.appendJob (job,result_array);
};
/**
......@@ -1304,11 +1376,11 @@ var jobManager = (function(spec, my) {
* @return {array} A result array.
*/
that.validateJobAccordingToJobList = function(job_array,job) {
var i, result_a = [];
var i, result_array = [];
for (i = 0; i < job_array.length; i+= 1) {
result_a.push(jobRules.validateJobAccordingToJob (job_array[i],job));
result_array.push(jobRules.validateJobAccordingToJob (job_array[i],job));
}
return result_a;
return result_array;
};
/**
......@@ -1318,30 +1390,30 @@ var jobManager = (function(spec, my) {
* one, to replace one or to eliminate some while browsing.
* @method appendJob
* @param {object} job The job to append.
* @param {array} result_a The result array.
* @param {array} result_array The result array.
*/
priv.appendJob = function(job,result_a) {
priv.appendJob = function(job,result_array) {
var i;
if (priv.job_array.length !== result_a.length) {
if (priv.job_array.length !== result_array.length) {
throw new RangeError("Array out of bound");
}
for (i = 0; i < result_a.length; i+= 1) {
if (result_a[i].action === 'dont accept') {
for (i = 0; i < result_array.length; i+= 1) {
if (result_array[i].action === 'dont accept') {
return job.notAccepted();
}
}
for (i = 0; i < result_a.length; i+= 1) {
switch (result_a[i].action) {
for (i = 0; i < result_array.length; i+= 1) {
switch (result_array[i].action) {
case 'eliminate':
result_a[i].job.eliminated();
priv.removeJob(result_a[i].job);
result_array[i].job.eliminated();
priv.removeJob(result_array[i].job);
break;
case 'update':
result_a[i].job.update(job);
result_array[i].job.update(job);
priv.copyJobArrayToLocal();
return;
case 'wait':
job.waitForJob(result_a[i].job);
job.waitForJob(result_array[i].job);
break;
default: break;
}
......@@ -1375,7 +1447,12 @@ var jobRules = (function(spec, my) {
that.none = function() { return 'none'; };
that.default_action = that.none;
that.default_compare = function(job1,job2) {
return (job1.getCommand().getPath() === job2.getCommand().getPath() &&
return (job1.getCommand().getDocId() ===
job2.getCommand().getDocId() &&
job1.getCommand().getDocInfo('_rev') ===
job2.getCommand().getDocInfo('_rev') &&
job1.getCommand().getOption('rev') ===
job2.getCommand().getOption('rev') &&
JSON.stringify(job1.getStorage().serialized()) ===
JSON.stringify(job2.getStorage().serialized()));
};
......@@ -1515,36 +1592,36 @@ var jobRules = (function(spec, my) {
For more information, see documentation
*/
that.addActionRule ('saveDocument',true,'saveDocument',
function(job1,job2){
if (job1.getCommand().getContent() ===
job2.getCommand().getContent()) {
return that.dontAccept();
} else {
return that.wait();
}
});
that.addActionRule('saveDocument' ,true ,'loadDocument' ,that.wait);
that.addActionRule('saveDocument' ,true ,'removeDocument' ,that.wait);
that.addActionRule('saveDocument' ,false,'saveDocument' ,that.update);
that.addActionRule('saveDocument' ,false,'loadDocument' ,that.wait);
that.addActionRule('saveDocument' ,false,'removeDocument' ,that.eliminate);
that.addActionRule('loadDocument' ,true ,'saveDocument' ,that.wait);
that.addActionRule('loadDocument' ,true ,'loadDocument' ,that.dontAccept);
that.addActionRule('loadDocument' ,true ,'removeDocument' ,that.wait);
that.addActionRule('loadDocument' ,false,'saveDocument' ,that.wait);
that.addActionRule('loadDocument' ,false,'loadDocument' ,that.update);
that.addActionRule('loadDocument' ,false,'removeDocument' ,that.wait);
that.addActionRule('removeDocument' ,true ,'loadDocument' ,that.dontAccept);
that.addActionRule('removeDocument' ,true ,'removeDocument' ,that.dontAccept);
that.addActionRule('removeDocument' ,false,'saveDocument' ,that.eliminate);
that.addActionRule('removeDocument' ,false,'loadDocument' ,that.dontAccept);
that.addActionRule('removeDocument' ,false,'removeDocument' ,that.update);
that.addActionRule('getDocumentList',true ,'getDocumentList',that.dontAccept);
that.addActionRule('getDocumentList',false,'getDocumentList',that.update);
that.addActionRule ('put' ,true,'put',
function(job1,job2){
if (job1.getCommand().getDocInfo('content') ===
job2.getCommand().getDocInfo('content')) {
return that.dontAccept();
} else {
return that.wait();
}
});
that.addActionRule('put' ,true ,'get' ,that.wait);
that.addActionRule('put' ,true ,'remove' ,that.wait);
that.addActionRule('put' ,false,'put' ,that.update);
that.addActionRule('put' ,false,'get' ,that.wait);
that.addActionRule('put' ,false,'remove' ,that.eliminate);
that.addActionRule('get' ,true ,'put' ,that.wait);
that.addActionRule('get' ,true ,'get' ,that.dontAccept);
that.addActionRule('get' ,true ,'remove' ,that.wait);
that.addActionRule('get' ,false,'put' ,that.wait);
that.addActionRule('get' ,false,'get' ,that.update);
that.addActionRule('get' ,false,'remove' ,that.wait);
that.addActionRule('remove' ,true ,'get' ,that.dontAccept);
that.addActionRule('remove' ,true ,'remove' ,that.dontAccept);
that.addActionRule('remove' ,false,'put' ,that.eliminate);
that.addActionRule('remove' ,false,'get' ,that.dontAccept);
that.addActionRule('remove' ,false,'remove' ,that.update);
that.addActionRule('allDocs',true ,'allDocs',that.dontAccept);
that.addActionRule('allDocs',false,'allDocs',that.update);
// end adding rules
////////////////////////////////////////////////////////////////////////////
return that;
......@@ -1630,107 +1707,168 @@ var jobRules = (function(spec, my) {
return jobManager.serialized();
};
/**
* Save a document.
* @method saveDocument
* @param {string} path The document path name.
* @param {string} content The document's content.
* @param {object} option (optional) Contains some options:
* - {function} success The callback called when the job has passed.
* - {function} error The callback called when the job has fail.
* - {number} max_retry The number max of retries, 0 = infinity.
* @param {object} specificstorage (optional) A specific storage, only if
* you want to save this document elsewhere.
*/
that.saveDocument = function(path, content, option, specificstorage) {
option = option || {};
option.success = option.success || function(){};
option.error = option.error || function(){};
option.max_retry = option.max_retry || 0;
priv.getParam = function (list,nodoc) {
var param = {}, i = 0;
if (!nodoc) {
param.doc = list[i];
i ++;
}
if (typeof list[i] === 'object') {
param.options = list[i];
i ++;
} else {
param.options = {};
}
param.callback = function (err,val){};
param.success = function (val) {
param.callback(undefined,val);
};
param.error = function (err) {
param.callback(err,undefined);
};
if (typeof list[i] === 'function') {
if (typeof list[i+1] === 'function') {
param.success = list[i];
param.error = list[i+1];
} else {
param.callback = list[i];
}
}
return param;
};
priv.addJob = function (commandCreator,spec) {
jobManager.addJob(
job({storage:(specificstorage?
jioNamespace.storage(specificstorage,my):
jioNamespace.storage(priv.storage_spec,my)),
command:saveDocument(
{path:path,content:content,option:option},my)},my));
job({storage:jioNamespace.storage(priv.storage_spec,my),
command:commandCreator(spec,my)},my));
};
// /**
// * Post a document.
// * @method post
// * @param {object} doc The document {"content":}.
// * @param {object} options (optional) Contains some options:
// * - {number} max_retry The number max of retries, 0 = infinity.
// * - {boolean} revs Include revision history of the document.
// * - {boolean} revs_info Retreive the revisions.
// * - {boolean} conflicts Retreive the conflict list.
// * @param {function} callback (optional) The callback(err,response).
// * @param {function} error (optional) The callback on error, if this
// * callback is given in parameter, "callback" is changed as "success",
// * called on success.
// */
// that.post = function() {
// var param = priv.getParam(arguments);
// param.options.max_retry = param.options.max_retry || 0;
// priv.addJob(postCommand,{
// doc:param.doc,
// options:param.options,
// callbacks:{success:param.success,error:param.error}
// });
// };
/**
* Put a document.
* @method put
* @param {object} doc The document {"_id":,"_rev":,"content":}.
* @param {object} options (optional) Contains some options:
* - {number} max_retry The number max of retries, 0 = infinity.
* - {boolean} revs Include revision history of the document.
* - {boolean} revs_info Retreive the revisions.
* - {boolean} conflicts Retreive the conflict list.
* @param {function} callback (optional) The callback(err,response).
* @param {function} error (optional) The callback on error, if this
* callback is given in parameter, "callback" is changed as "success",
* called on success.
*/
that.put = function() {
var param = priv.getParam(arguments);
param.options.max_retry = param.options.max_retry || 0;
priv.addJob(putCommand,{
doc:param.doc,
options:param.options,
callbacks:{success:param.success,error:param.error}
});
};
/**
* Load a document.
* @method loadDocument
* @param {string} path The document path name.
* @param {object} option (optional) Contains some options:
* - {function} success The callback called when the job has passed.
* - {function} error The callback called when the job has fail.
* Get a document.
* @method get
* @param {string} docid The document id (the path).
* @param {object} options (optional) Contains some options:
* - {number} max_retry The number max of retries, 0 = infinity.
* - {boolean} metadata_only Load only document metadata.
* @param {object} specificstorage (optional) A specific storage, only if
* you want to save this document elsewhere.
*/
that.loadDocument = function(path, option, specificstorage) {
option = option || {};
option.success = option.success || function(){};
option.error = option.error || function(){};
option.max_retry = option.max_retry || 3;
option.metadata_only = (option.metadata_only !== undefined?
option.metadata_only:false);
jobManager.addJob(
job({storage:(specificstorage?
jioNamespace.storage(specificstorage,my):
jioNamespace.storage(priv.storage_spec,my)),
command:loadDocument(
{path:path,option:option},my)},my));
* - {string} rev The revision we want to get.
* - {boolean} revs Include revision history of the document.
* - {boolean} revs_info Include list of revisions, and their availability.
* - {boolean} conflicts Include a list of conflicts.
* @param {function} callback (optional) The callback(err,response).
* @param {function} error (optional) The callback on error, if this
* callback is given in parameter, "callback" is changed as "success",
* called on success.
*/
that.get = function() {
var param = priv.getParam(arguments);
param.options.max_retry = param.options.max_retry || 3;
param.options.metadata_only = (
param.options.metadata_only !== undefined?
param.options.metadata_only:false);
priv.addJob(getCommand,{
docid:param.doc,
options:param.options,
callbacks:{success:param.success,error:param.error}
});
};
/**
* Remove a document.
* @method removeDocument
* @param {string} path The document path name.
* @param {object} option (optional) Contains some options:
* - {function} success The callback called when the job has passed.
* - {function} error The callback called when the job has fail.
* @method remove
* @param {object} doc The document {"_id":,"_rev":}.
* @param {object} options (optional) Contains some options:
* - {number} max_retry The number max of retries, 0 = infinity.
* @param {object} specificstorage (optional) A specific storage, only if
* you want to save this document elsewhere.
*/
that.removeDocument = function(path, option, specificstorage) {
option = option || {};
option.success = option.success || function(){};
option.error = option.error || function(){};
option.max_retry = option.max_retry || 0;
jobManager.addJob(
job({storage:(specificstorage?
jioNamespace.storage(specificstorage,my):
jioNamespace.storage(priv.storage_spec,my)),
command:removeDocument(
{path:path,option:option},my)},my));
* - {boolean} revs Include revision history of the document.
* - {boolean} revs_info Include list of revisions, and their availability.
* - {boolean} conflicts Include a list of conflicts.
* @param {function} callback (optional) The callback(err,response).
* @param {function} error (optional) The callback on error, if this
* callback is given in parameter, "callback" is changed as "success",
* called on success.
*/
that.remove = function() {
var param = priv.getParam(arguments);
param.options.max_retry = param.options.max_retry || 0;
priv.addJob(removeCommand,{
doc:param.doc,
options:param.options,
callbacks:{success:param.success,error:param.error}
});
};
/**
* Get a document list from a folder.
* @method getDocumentList
* @param {string} path The folder path.
* @param {object} option (optional) Contains some options:
* - {function} success The callback called when the job has passed.
* - {function} error The callback called when the job has fail.
* Get a list of documents.
* @method allDocs
* @param {object} options (optional) Contains some options:
* - {number} max_retry The number max of retries, 0 = infinity.
* - {boolean} metadata_only Load only document metadata
* @param {object} specificstorage (optional) A specific storage, only if
* you want to save this document elsewhere.
*/
that.getDocumentList = function(path, option, specificstorage) {
option = option || {};
option.success = option.success || function(){};
option.error = option.error || function(){};
option.max_retry = option.max_retry || 3;
option.metadata_only = (option.metadata_only !== undefined?
option.metadata_only:true);
jobManager.addJob(
job({storage:(specificstorage?
jioNamespace.storage(specificstorage,my):
jioNamespace.storage(priv.storage_spec,my)),
command:getDocumentList(
{path:path,option:option},my)},my));
* - {boolean} descending Reverse the order of the output table.
* - {boolean} revs Include revision history of the document.
* - {boolean} revs_info Include revisions.
* - {boolean} conflicts Include conflicts.
* @param {function} callback (optional) The callback(err,response).
* @param {function} error (optional) The callback on error, if this
* callback is given in parameter, "callback" is changed as "success",
* called on success.
*/
that.allDocs = function() {
var param = priv.getParam(arguments,'no doc');
param.options.max_retry = param.options.max_retry || 3;
param.options.metadata_only = (
param.options.metadata_only !== undefined?
param.options.metadata_only:true);
priv.addJob(allDocsCommand,{
options:param.options,
callbacks:{success:param.success,error:param.error}
});
};
return that;
......
/*! JIO - v0.1.0 - 2012-08-01
/*! JIO - v0.1.0 - 2012-08-14
* Copyright (c) 2012 Nexedi; Licensed */
var jio=function(){var a=function(a,b){var c={};return a=a||{},b=b||{},c.name="jioException",c.message=a.message||"Unknown Reason.",c.toString=function(){return c.name+": "+c.message},c},b=function(b,c){var d=a(b,c);b=b||{};var e=b.command;return d.name="invalidCommandState",d.toString=function(){return d.name+": "+e.getLabel()+", "+d.message},d},c=function(b,c){var d=a(b,c);b=b||{};var e=b.storage.getType();return d.name="invalidStorage",d.toString=function(){return d.name+": "+'Type "'+e+'", '+d.message},d},d=function(b,c){var d=a(b,c),e=b.type;return d.name="invalidStorageType",d.toString=function(){return d.name+": "+e+", "+d.message},d},e=function(b,c){var d=a(b,c);return d.name="jobNotReadyException",d},f=function(b,c){var d=a(b,c);return d.name="tooMuchTriesJobException",d},g=function(b,c){var d=a(b,c);return d.name="invalidJobException",d},h=function(a,b){var d={};a=a||{},b=b||{};var e={};return e.type=a.type||"",d.getType=function(){return e.type},d.setType=function(a){e.type=a},d.execute=function(a){d.validate(a),d.success=a.success,d.error=a.error,d.retry=a.retry,d.end=a.end,a.executeOn(d)},d.isValid=function(){return!0},d.validate=function(a){var b=d.validateState();if(b)throw c({storage:d,message:b});a.validate(d)},d.serialized=function(){return{type:d.getType()}},d.saveDocument=function(a){throw c({storage:d,message:"Unknown storage."})},d.loadDocument=function(a){d.saveDocument()},d.removeDocument=function(a){d.saveDocument()},d.getDocumentList=function(a){d.saveDocument()},d.validateState=function(){return""},d.success=function(){},d.retry=function(){},d.error=function(){},d.end=function(){},d},i=function(a,b){a=a||{},b=b||{};var c=h(a,b);return c.newCommand=function(a,c){var d=c||{};return d.label=a,j(d,b)},c.newStorage=function(a){var c=a||{};return x.storage(c,b)},c.addJob=function(a,c){b.jobManager.addJob(u({storage:a,command:c},b))},c},j=function(a,c){var d={};a=a||{},c=c||{};var e={};return e.commandlist={saveDocument:n,loadDocument:l,removeDocument:m,getDocumentList:k},a.label&&e.commandlist[a.label]?(e.label=a.label,delete a.label,e.commandlist[e.label](a,c)):(e.path=a.path||"",e.tried=0,e.option=a.option||{},e.success=e.option.success||function(){},e.error=e.option.error||function(){},e.retry=function(){d.error({status:13,statusText:"Fail Retry",message:"Impossible to retry."})},e.end=function(){},e.on_going=!1,d.serialized=function(){return{label:d.getLabel(),tried:e.tried,max_retry:e.max_retry,path:e.path,option:d.cloneOption()}},d.getLabel=function(){return"command"},d.getPath=function(){return e.path},d.getOption=function(a){return e.option[a]},d.validate=function(a){d.validateState()},d.canBeRetried=function(){return e.option.max_retry===0||e.tried<e.option.max_retry},d.getTried=function(){return e.tried},d.execute=function(a){e.on_going||(d.validate(a),e.tried++,e.on_going=!0,a.execute(d))},d.executeOn=function(a){},d.validateState=function(){if(e.path==="")throw b({command:d,message:"Path is empty"})},d.success=function(a){e.on_going=!1,e.success(a),e.end(p())},d.retry=function(a){e.on_going=!1,d.canBeRetried()?e.retry():d.error(a)},d.error=function(a){e.on_going=!1,e.error(a),e.end(q())},d.end=function(){e.end(p())},d.onSuccessDo=function(a){if(a)e.success=a;else return e.success},d.onErrorDo=function(a){if(a)e.error=a;else return e.error},d.onEndDo=function(a){e.end=a},d.onRetryDo=function(a){e.retry=a},d.canBeRestored=function(){return!0},d.clone=function(){return j(d.serialized(),c)},d.cloneOption=function(){var a,b={};for(a in e.option)b[a]=e.option[a];return b},d)},k=function(a,b){var c=j(a,b);a=a||{},b=b||{},c.getLabel=function(){return"getDocumentList"},c.executeOn=function(a){a.getDocumentList(c)},c.canBeRestored=function(){return!1};var d=c.success;return c.success=function(a){var b;if(a)for(b=0;b<a.length;b+=1)typeof a[b].last_modified!="number"&&(a[b].last_modified=(new Date(a[b].last_modified)).getTime()),typeof a[b].creation_date!="number"&&(a[b].creation_date=(new Date(a[b].creation_date)).getTime());d(a)},c},l=function(a,b){var c=j(a,b);a=a||{},b=b||{},c.getLabel=function(){return"loadDocument"},c.executeOn=function(a){a.loadDocument(c)},c.canBeRestored=function(){return!1};var d=c.success;return c.success=function(a){a&&(typeof a.last_modified!="number"&&(a.last_modified=(new Date(a.last_modified)).getTime()),typeof a.creation_date!="number"&&(a.creation_date=(new Date(a.creation_date)).getTime())),d(a)},c},m=function(a,b){var c=j(a,b);return a=a||{},b=b||{},c.getLabel=function(){return"removeDocument"},c.executeOn=function(a){a.removeDocument(c)},c},n=function(a,c){var d=j(a,c);a=a||{},c=c||{};var e={};e.content=a.content,d.getLabel=function(){return"saveDocument"},d.getContent=function(){return e.content};var f=d.validate;d.validate=function(a){if(typeof e.content!="string")throw b({command:d,message:"No data to save"});f(a)},d.executeOn=function(a){a.saveDocument(d)};var g=d.serialized;return d.serialized=function(){var a=g();return a.content=e.content,a},d},o=function(a,b){var c={};return a=a||{},b=b||{},c.getLabel=function(){return"job status"},c.canStart=function(){},c.canRestart=function(){},c.serialized=function(){return{label:c.getLabel()}},c.isWaitStatus=function(){return!1},c.isDone=function(){return!1},c},p=function(a,b){var c=o(a,b);return a=a||{},b=b||{},c.getLabel=function(){return"done"},c.canStart=function(){return!1},c.canRestart=function(){return!1},c.isDone=function(){return!0},c},q=function(a,b){var c=o(a,b);return a=a||{},b=b||{},c.getLabel=function(){return"fail"},c.canStart=function(){return!1},c.canRestart=function(){return!0},c},r=function(a,b){var c=o(a,b);return a=a||{},b=b||{},c.getLabel=function(){return"initial"},c.canStart=function(){return!0},c.canRestart=function(){return!0},c},s=function(a,b){var c=o(a,b);return a=a||{},b=b||{},c.getLabel=function(){return"on going"},c.canStart=function(){return!1},c.canRestart=function(){return!1},c},t=function(a,b){var c=o(a,b);a=a||{},b=b||{};var d={};return d.job_id_array=a.job_id_array||[],d.threshold=0,c.getLabel=function(){return"wait"},d.refreshJobIdArray=function(){var a=[],c;for(c=0;c<d.job_id_array.length;c+=1)b.jobManager.jobIdExists(d.job_id_array[c])&&a.push(d.job_id_array[c]);d.job_id_array=a},c.waitForJob=function(a){var b;for(b=0;b<d.job_id_array.length;b+=1)if(d.job_id_array[b]===a.getId())return;d.job_id_array.push(a.getId())},c.dontWaitForJob=function(a){var b,c=[];for(b=0;b<d.job_id_array.length;b+=1)d.job_id_array[b]!==a.getId()&&c.push(d.job_id_array[b]);d.job_id_array=c},c.waitForTime=function(a){d.threshold=Date.now()+a},c.stopWaitForTime=function(){d.threshold=0},c.canStart=function(){return d.refreshJobIdArray(),d.job_id_array.length===0&&Date.now()>=d.threshold},c.canRestart=function(){return c.canStart()},c.serialized=function(){return{label:c.getLabel(),waitfortime:d.threshold,waitforjob:d.job_id_array}},c.isWaitStatus=function(){return!0},c},u=function(a,b){var c={};a=a||{},b=b||{};var d={};d.id=b.jobIdHandler.nextId(),d.command=a.command,d.storage=a.storage,d.status=r(),d.date=new Date;if(!d.storage)throw g({job:c,message:"No storage set"});if(!d.command)throw g({job:c,message:"No command set"});return c.getCommand=function(){return d.command},c.getStatus=function(){return d.status},c.getId=function(){return d.id},c.getStorage=function(){return d.storage},c.getDate=function(){return d.date},c.isReady=function(){return c.getCommand().getTried()===0?d.status.canStart():d.status.canRestart()},c.serialized=function(){return{id:d.id,date:d.date.getTime(),status:d.status.serialized(),command:d.command.serialized(),storage:d.storage.serialized()}},c.waitForJob=function(a){d.status.getLabel()!=="wait"&&(d.status=t({},b)),d.status.waitForJob(a)},c.dontWaitFor=function(a){d.status.getLabel()==="wait"&&d.status.dontWaitForJob(a)},c.waitForTime=function(a){d.status.getLabel()!=="wait"&&(d.status=t({},b)),d.status.waitForTime(a)},c.stopWaitForTime=function(){d.status.getLabel()==="wait"&&d.status.stopWaitForTime()},c.eliminated=function(){d.command.error({status:10,statusText:"Stoped",message:"This job has been stoped by another one."})},c.notAccepted=function(){d.command.onEndDo(function(){d.status=q(),b.jobManager.terminateJob(c)}),d.command.error({status:11,statusText:"Not Accepted",message:"This job is already running."})},c.update=function(a){d.command.error({status:12,statusText:"Replaced",message:"Job has been replaced by another one."}),d.date=a.getDate(),d.command=a.getCommand(),d.status=a.getStatus()},c.execute=function(){if(!c.getCommand().canBeRetried())throw f({job:c,message:"The job was invoked too much time."});if(!c.isReady())throw e({job:c,message:"Can not execute this job."});d.status=s(),d.command.onRetryDo(function(){var a=d.command.getTried();a=a*a*200,a>1e4&&(a=1e4),c.waitForTime(a)}),d.command.onEndDo(function(a){d.status=a,b.jobManager.terminateJob(c)}),d.command.execute(d.storage)},c},v=function(a,b){var c={};a=a||{},b=b||{};var d=[],e=a.name||"",f=a.announcer||{};return c.add=function(a){d.push(a)},c.remove=function(a){var b,c=[];for(b=0;b<d.length;b+=1)d[b]!==a&&c.push(d[b]);d=c},c.register=function(){f.register(c)},c.unregister=function(){f.unregister(c)},c.trigger=function(a){var b;for(b=0;b<d.length;b++)d[b].apply(null,a)},c},w=function(a,b){var c=function(a,b){var c={};a=a||{},b=b||{};var d={};return d.id=a.id||0,d.interval=400,d.interval_id=null,d.touch=function(){LocalOrCookieStorage.setItem("jio/id/"+d.id,Date.now())},c.setId=function(a){d.id=a},c.setIntervalDelay=function(a){d.interval=a},c.getIntervalDelay=function(){return d.interval},c.start=function(){d.interval_id||(d.touch(),d.interval_id=setInterval(function(){d.touch()},d.interval))},c.stop=function(){d.interval_id!==null&&(clearInterval(d.interval_id),d.interval_id=null)},c}(),d=function(a,b){var c={};a=a||{},b=b||{};var d={};return c.register=function(a){d[a]||(d[a]=v())},c.unregister=function(a){d[a]&&delete d[a]},c.at=function(a){return d[a]},c.on=function(a,b){c.register(a),c.at(a).add(b)},c.trigger=function(a,b){c.at(a).trigger(b)},c}(),e=function(a,b){var c={};a=a||{},b=b||{};var d=0;return c.nextId=function(){return d=d+1,d},c}(),f=function(a,b){var c={};a=a||{},b=b||{};var d="jio/job_array",f={};return f.id=a.id,f.interval_id=null,f.interval=200,f.job_array=[],b.jobManager=c,b.jobIdHandler=e,f.getJobArrayName=function(){return d+"/"+f.id},f.getJobArray=function(){return LocalOrCookieStorage.getItem(f.getJobArrayName())||[]},f.copyJobArrayToLocal=function(){var a=[],b;for(b=0;b<f.job_array.length;b+=1)a.push(f.job_array[b].serialized());LocalOrCookieStorage.setItem(f.getJobArrayName(),a)},f.removeJob=function(a){var b,c=[];for(b=0;b<f.job_array.length;b+=1)f.job_array[b]!==a&&c.push(f.job_array[b]);f.job_array=c,f.copyJobArrayToLocal()},c.setId=function(a){f.id=a},c.start=function(){var a;f.interval_id===null&&(f.interval_id=setInterval(function(){f.restoreOldJio();for(a=0;a<f.job_array.length;a+=1)c.execute(f.job_array[a])},f.interval))},c.stop=function(){f.interval_id!==null&&(clearInterval(f.interval_id),f.interval_id=null,f.job_array.length===0&&LocalOrCookieStorage.deleteItem(f.getJobArrayName()))},f.restoreOldJio=function(){var a,b;f.lastrestore=f.lastrestore||0;if(f.lastrestore>Date.now()-2e3)return;b=LocalOrCookieStorage.getItem("jio/id_array")||[];for(a=0;a<b.length;a+=1)f.restoreOldJioId(b[a]);f.lastrestore=Date.now()},f.restoreOldJioId=function(a){var b;b=LocalOrCookieStorage.getItem("jio/id/"+a)||0,b<Date.now()-1e4&&(f.restoreOldJobFromJioId(a),f.removeOldJioId(a),f.removeJobArrayFromJioId(a))},f.restoreOldJobFromJioId=function(a){var d,e;e=LocalOrCookieStorage.getItem("jio/job_array/"+a)||[];for(d=0;d<e.length;d+=1){var f=j(e[d].command,b);f.canBeRestored()&&c.addJob(u({storage:x.storage(e[d].storage,b),command:f},b))}},f.removeOldJioId=function(a){var b,c,d=[];c=LocalOrCookieStorage.getItem("jio/id_array")||[];for(b=0;b<c.length;b+=1)c[b]!==a&&d.push(c[b]);LocalOrCookieStorage.setItem("jio/id_array",d),LocalOrCookieStorage.deleteItem("jio/id/"+a)},f.removeJobArrayFromJioId=function(a){LocalOrCookieStorage.deleteItem("jio/job_array/"+a)},c.execute=function(a){try{a.execute()}catch(b){switch(b.name){case"jobNotReadyException":break;case"tooMuchTriesJobException":break;default:throw b}}f.copyJobArrayToLocal()},c.jobIdExists=function(a){var b;for(b=0;b<f.job_array.length;b+=1)if(f.job_array[b].getId()===a)return!0;return!1},c.terminateJob=function(a){f.removeJob(a)},c.addJob=function(a){var b=c.validateJobAccordingToJobList(f.job_array,a);f.appendJob(a,b)},c.validateJobAccordingToJobList=function(a,b){var c,d=[];for(c=0;c<a.length;c+=1)d.push(g.validateJobAccordingToJob(a[c],b));return d},f.appendJob=function(a,b){var c;if(f.job_array.length!==b.length)throw new RangeError("Array out of bound");for(c=0;c<b.length;c+=1)if(b[c].action==="dont accept")return a.notAccepted();for(c=0;c<b.length;c+=1)switch(b[c].action){case"eliminate":b[c].job.eliminated(),f.removeJob(b[c].job);break;case"update":b[c].job.update(a),f.copyJobArrayToLocal();return;case"wait":a.waitForJob(b[c].job);break;default:}f.job_array.push(a),f.copyJobArrayToLocal()},c.serialized=function(){var a=[],b,c=f.job_array||[];for(b=0;b<c.length;b+=1)a.push(c[b].serialized());return a},c}(),g=function(a,b){var c={},d={};return d.compare={},d.action={},c.eliminate=function(){return"eliminate"},c.update=function(){return"update"},c.dontAccept=function(){return"dont accept"},c.wait=function(){return"wait"},c.none=function(){return"none"},c.default_action=c.none,c.default_compare=function(a,b){return a.getCommand().getPath()===b.getCommand().getPath()&&JSON.stringify(a.getStorage().serialized())===JSON.stringify(b.getStorage().serialized())},d.getAction=function(a,b){var e,f,g;return e=a.getCommand().getLabel(),f=b.getCommand().getLabel(),g=a.getStatus().getLabel()==="on going"?"on going":"not on going",d.action[e]&&d.action[e][g]&&d.action[e][g][f]?d.action[e][g][f](a,b):c.default_action(a,b)},d.canCompare=function(a,b){var e=a.getCommand().getLabel(),f=b.getCommand().getLabel();return d.compare[e]&&d.compare[f]?d.compare[e][f](a,b):c.default_compare(a,b)},c.validateJobAccordingToJob=function(a,b){return d.canCompare(a,b)?{action:d.getAction(a,b),job:a}:{action:c.default_action(a,b),job:a}},c.addActionRule=function(a,b,c,e){var f=b?"on going":"not on going";d.action[a]=d.action[a]||{},d.action[a][f]=d.action[a][f]||{},d.action[a][f][c]=e},c.addCompareRule=function(a,b,c){d.compare[a]=d.compare[a]||{},d.compare[a][b]=c},c.addActionRule("saveDocument",!0,"saveDocument",function(a,b){return a.getCommand().getContent()===b.getCommand().getContent()?c.dontAccept():c.wait()}),c.addActionRule("saveDocument",!0,"loadDocument",c.wait),c.addActionRule("saveDocument",!0,"removeDocument",c.wait),c.addActionRule("saveDocument",!1,"saveDocument",c.update),c.addActionRule("saveDocument",!1,"loadDocument",c.wait),c.addActionRule("saveDocument",!1,"removeDocument",c.eliminate),c.addActionRule("loadDocument",!0,"saveDocument",c.wait),c.addActionRule("loadDocument",!0,"loadDocument",c.dontAccept),c.addActionRule("loadDocument",!0,"removeDocument",c.wait),c.addActionRule("loadDocument",!1,"saveDocument",c.wait),c.addActionRule("loadDocument",!1,"loadDocument",c.update),c.addActionRule("loadDocument",!1,"removeDocument",c.wait),c.addActionRule("removeDocument",!0,"loadDocument",c.dontAccept),c.addActionRule("removeDocument",!0,"removeDocument",c.dontAccept),c.addActionRule("removeDocument",!1,"saveDocument",c.eliminate),c.addActionRule("removeDocument",!1,"loadDocument",c.dontAccept),c.addActionRule("removeDocument",!1,"removeDocument",c.update),c.addActionRule("getDocumentList",!0,"getDocumentList",c.dontAccept),c.addActionRule("getDocumentList",!1,"getDocumentList",c.update),c}(),h={};a=a||{},b=b||{};var i={},o="jio/id_array";return i.id=null,b.jobManager=f,b.jobIdHandler=e,i.storage_spec=a,i.init=function(){if(i.id===null){var a,b=LocalOrCookieStorage.getItem(o)||[];i.id=1;for(a=0;a<b.length;a+=1)b[a]>=i.id&&(i.id=b[a]+1);b.push(i.id),LocalOrCookieStorage.setItem(o,b),c.setId(i.id),f.setId(i.id)}},h.start=function(){i.init(),c.start(),f.start()},h.stop=function(){f.stop()},h.close=function(){c.stop(),f.stop(),i.id=null},h.start(),h.getId=function(){return i.id},h.getJobRules=function(){return g},h.validateStorageDescription=function(a){return x.storage(a,b).isValid()},h.getJobArray=function(){return f.serialized()},h.saveDocument=function(a,c,d,e){d=d||{},d.success=d.success||function(){},d.error=d.error||function(){},d.max_retry=d.max_retry||0,f.addJob(u({storage:e?x.storage(e,b):x.storage(i.storage_spec,b),command:n({path:a,content:c,option:d},b)},b))},h.loadDocument=function(a,c,d){c=c||{},c.success=c.success||function(){},c.error=c.error||function(){},c.max_retry=c.max_retry||3,c.metadata_only=c.metadata_only!==undefined?c.metadata_only:!1,f.addJob(u({storage:d?x.storage(d,b):x.storage(i.storage_spec,b),command:l({path:a,option:c},b)},b))},h.removeDocument=function(a,c,d){c=c||{},c.success=c.success||function(){},c.error=c.error||function(){},c.max_retry=c.max_retry||0,f.addJob(u({storage:d?x.storage(d,b):x.storage(i.storage_spec,b),command:m({path:a,option:c},b)},b))},h.getDocumentList=function(a,c,d){c=c||{},c.success=c.success||function(){},c.error=c.error||function(){},c.max_retry=c.max_retry||3,c.metadata_only=c.metadata_only!==undefined?c.metadata_only:!0,f.addJob(u({storage:d?x.storage(d,b):x.storage(i.storage_spec,b),command:k({path:a,option:c},b)},b))},h},x=function(a,b){var c={};a=a||{},b=b||{};var e={base:h,handler:i};return c.storage=function(a,b,c){a=a||{},b=b||{};var f=c||a.type||"base";if(!e[f])throw d({type:f,message:"Storage does not exists."});return e[f](a,b)},c.newJio=function(a){var b=a;return typeof b=="string"&&(b=JSON.parse(b)),b=b||{type:"base"},w(a)},c.addStorageType=function(a,b){b=b||function(){return null};if(e[a])throw d({type:a,message:"Already known."});e[a]=b},c}();return x}();
\ No newline at end of file
var jio=function(){var a=function(a,b){var c={};return a=a||{},b=b||{},c.name="jioException",c.message=a.message||"Unknown Reason.",c.toString=function(){return c.name+": "+c.message},c},b=function(b,c){var d=a(b,c);b=b||{};var e=b.command;return d.name="invalidCommandState",d.toString=function(){return d.name+": "+e.getLabel()+", "+d.message},d},c=function(b,c){var d=a(b,c);b=b||{};var e=b.storage.getType();return d.name="invalidStorage",d.toString=function(){return d.name+": "+'Type "'+e+'", '+d.message},d},d=function(b,c){var d=a(b,c),e=b.type;return d.name="invalidStorageType",d.toString=function(){return d.name+": "+e+", "+d.message},d},e=function(b,c){var d=a(b,c);return d.name="jobNotReadyException",d},f=function(b,c){var d=a(b,c);return d.name="tooMuchTriesJobException",d},g=function(b,c){var d=a(b,c);return d.name="invalidJobException",d},h=function(a,b){var c={};a=a||{},b=b||{};var d={};return d.type=a.type||"",c.getType=function(){return d.type},c.setType=function(a){d.type=a},c.execute=function(a){c.success=a.success,c.error=a.error,c.retry=a.retry,c.end=a.end,c.validate(a)&&a.executeOn(c)},c.isValid=function(){return!0},c.validate=function(){var a=c.validateState();return a?(c.error({status:0,statusText:"Invalid Storage",error:"invalid_storage",message:a,reason:a}),!1):!0},c.serialized=function(){return{type:c.getType()}},c.saveDocument=function(a){c.error({status:0,statusText:"Unknown storage",error:"unknown_storage",message:"Unknown Storage"})},c.loadDocument=function(a){c.saveDocument()},c.removeDocument=function(a){c.saveDocument()},c.getDocumentList=function(a){c.saveDocument()},c.validateState=function(){return""},c.success=function(){},c.retry=function(){},c.error=function(){},c.end=function(){},c},i=function(a,b){a=a||{},b=b||{};var c=h(a,b),d={};return d.newCommand=function(a,c){var d=c||{};return d.label=a,j(d,b)},c.addJob=function(a,c,e,f,g,h){var i={options:f,callbacks:{success:g,error:h}};e&&(a==="get"?i.docid=e:i.doc=e),b.jobManager.addJob(v({storage:y.storage(c||{}),command:d.newCommand(a,i)},b))},c},j=function(a,b){var c={};a=a||{},b=b||{};var d={};return d.commandlist={post:o,put:n,get:l,remove:m,allDocs:k},a.label&&d.commandlist[a.label]?(d.label=a.label,delete a.label,d.commandlist[d.label](a,b)):(d.tried=0,d.doc=a.doc||{},d.docid=a.docid||"",d.option=a.options||{},d.callbacks=a.callbacks||{},d.success=d.callbacks.success||function(){},d.error=d.callbacks.error||function(){},d.retry=function(){c.error({status:13,statusText:"Fail Retry",error:"fail_retry",message:"Impossible to retry.",reason:"Impossible to retry."})},d.end=function(){},d.on_going=!1,c.serialized=function(){return{label:c.getLabel(),tried:d.tried,doc:c.cloneDoc(),option:c.cloneOption()}},c.getLabel=function(){return"command"},c.getDocId=function(){return d.docid||d.doc._id},c.getDocContent=function(){return d.doc.content},c.getDocInfo=function(a){return d.doc[a]},c.getOption=function(a){return d.option[a]},c.validate=function(a){return c.validateState()?a.validate():!1},c.validateState=function(){return typeof d.doc!="object"?(c.error({status:20,statusText:"Document_Id Required",error:"document_id_required",message:"No document id.",reason:"no document id"}),!1):!0},c.canBeRetried=function(){return typeof d.option.max_retry=="undefined"||d.option.max_retry===0||d.tried<d.option.max_retry},c.getTried=function(){return d.tried},c.execute=function(a){d.on_going||c.validate(a)&&(d.tried++,d.on_going=!0,a.execute(c))},c.executeOn=function(a){},c.success=function(a){d.on_going=!1,d.success(a),d.end(q())},c.retry=function(a){d.on_going=!1,c.canBeRetried()?d.retry():c.error(a)},c.error=function(a){d.on_going=!1,d.error(a),d.end(r())},c.end=function(){d.end(q())},c.onSuccessDo=function(a){if(a)d.success=a;else return d.success},c.onErrorDo=function(a){if(a)d.error=a;else return d.error},c.onEndDo=function(a){d.end=a},c.onRetryDo=function(a){d.retry=a},c.canBeRestored=function(){return!0},c.clone=function(){return j(c.serialized(),b)},c.cloneOption=function(){var a,b={};for(a in d.option)b[a]=d.option[a];return b},c.cloneDoc=function(){if(d.docid)return d.docid;var a,b={};for(a in d.doc)b[a]=d.doc[a];return b},c)},k=function(a,b){var c=j(a,b);return a=a||{},b=b||{},c.getLabel=function(){return"allDocs"},c.executeOn=function(a){a.allDocs(c)},c.canBeRestored=function(){return!1},c},l=function(a,b){var c=j(a,b);return a=a||{},b=b||{},c.getLabel=function(){return"get"},c.validateState=function(){return c.getDocId()?!0:(c.error({status:20,statusText:"Document Id Required",error:"document_id_required",message:"No document id.",reason:"no document id"}),!1)},c.executeOn=function(a){a.get(c)},c.canBeRestored=function(){return!1},c},m=function(a,b){var c=j(a,b);return a=a||{},b=b||{},c.getLabel=function(){return"remove"},c.executeOn=function(a){a.remove(c)},c},n=function(a,b){var c=j(a,b);a=a||{},b=b||{};var d={};c.getLabel=function(){return"put"};var e=c.validateState;return c.validate=function(){return typeof c.getDocInfo("content")!="string"?(c.error({status:21,statusText:"Content Required",error:"content_required",message:"No data to put.",reason:"no data to put"}),!1):e()},c.executeOn=function(a){a.put(c)},c},o=function(a,b){var c=j(a,b);a=a||{},b=b||{};var d={};c.getLabel=function(){return"post"};var e=c.validateState;return c.validate=function(){return typeof c.getDocInfo("content")!="string"?(c.error({status:21,statusText:"Content Required",error:"content_required",message:"No data to put.",reason:"no data to put"}),!1):e()},c.executeOn=function(a){a.put(c)},c},p=function(a,b){var c={};return a=a||{},b=b||{},c.getLabel=function(){return"job status"},c.canStart=function(){},c.canRestart=function(){},c.serialized=function(){return{label:c.getLabel()}},c.isWaitStatus=function(){return!1},c.isDone=function(){return!1},c},q=function(a,b){var c=p(a,b);return a=a||{},b=b||{},c.getLabel=function(){return"done"},c.canStart=function(){return!1},c.canRestart=function(){return!1},c.isDone=function(){return!0},c},r=function(a,b){var c=p(a,b);return a=a||{},b=b||{},c.getLabel=function(){return"fail"},c.canStart=function(){return!1},c.canRestart=function(){return!0},c},s=function(a,b){var c=p(a,b);return a=a||{},b=b||{},c.getLabel=function(){return"initial"},c.canStart=function(){return!0},c.canRestart=function(){return!0},c},t=function(a,b){var c=p(a,b);return a=a||{},b=b||{},c.getLabel=function(){return"on going"},c.canStart=function(){return!1},c.canRestart=function(){return!1},c},u=function(a,b){var c=p(a,b);a=a||{},b=b||{};var d={};return d.job_id_array=a.job_id_array||[],d.threshold=0,c.getLabel=function(){return"wait"},d.refreshJobIdArray=function(){var a=[],c;for(c=0;c<d.job_id_array.length;c+=1)b.jobManager.jobIdExists(d.job_id_array[c])&&a.push(d.job_id_array[c]);d.job_id_array=a},c.waitForJob=function(a){var b;for(b=0;b<d.job_id_array.length;b+=1)if(d.job_id_array[b]===a.getId())return;d.job_id_array.push(a.getId())},c.dontWaitForJob=function(a){var b,c=[];for(b=0;b<d.job_id_array.length;b+=1)d.job_id_array[b]!==a.getId()&&c.push(d.job_id_array[b]);d.job_id_array=c},c.waitForTime=function(a){d.threshold=Date.now()+a},c.stopWaitForTime=function(){d.threshold=0},c.canStart=function(){return d.refreshJobIdArray(),d.job_id_array.length===0&&Date.now()>=d.threshold},c.canRestart=function(){return c.canStart()},c.serialized=function(){return{label:c.getLabel(),waitfortime:d.threshold,waitforjob:d.job_id_array}},c.isWaitStatus=function(){return!0},c},v=function(a,b){var c={};a=a||{},b=b||{};var d={};d.id=b.jobIdHandler.nextId(),d.command=a.command,d.storage=a.storage,d.status=s(),d.date=new Date;if(!d.storage)throw g({job:c,message:"No storage set"});if(!d.command)throw g({job:c,message:"No command set"});return c.getCommand=function(){return d.command},c.getStatus=function(){return d.status},c.getId=function(){return d.id},c.getStorage=function(){return d.storage},c.getDate=function(){return d.date},c.isReady=function(){return d.command.getTried()===0?d.status.canStart():d.status.canRestart()},c.serialized=function(){return{id:d.id,date:d.date.getTime(),status:d.status.serialized(),command:d.command.serialized(),storage:d.storage.serialized()}},c.waitForJob=function(a){d.status.getLabel()!=="wait"&&(d.status=u({},b)),d.status.waitForJob(a)},c.dontWaitFor=function(a){d.status.getLabel()==="wait"&&d.status.dontWaitForJob(a)},c.waitForTime=function(a){d.status.getLabel()!=="wait"&&(d.status=u({},b)),d.status.waitForTime(a)},c.stopWaitForTime=function(){d.status.getLabel()==="wait"&&d.status.stopWaitForTime()},c.eliminated=function(){d.command.error({status:10,statusText:"Stopped",error:"stopped",message:"This job has been stoped by another one.",reason:this.message})},c.notAccepted=function(){d.command.onEndDo(function(){d.status=r(),b.jobManager.terminateJob(c)}),d.command.error({status:11,statusText:"Not Accepted",error:"not_accepted",message:"This job is already running.",reason:this.message})},c.update=function(a){d.command.error({status:12,statusText:"Replaced",error:"replaced",message:"Job has been replaced by another one.",reason:"job has been replaced by another one"}),d.date=new Date(a.getDate().getTime()),d.command=a.getCommand(),d.status=a.getStatus()},c.execute=function(){if(!c.getCommand().canBeRetried())throw f({job:c,message:"The job was invoked too much time."});if(!c.isReady())throw e({job:c,message:"Can not execute this job."});d.status=t(),d.command.onRetryDo(function(){var a=d.command.getTried();a=a*a*200,a>1e4&&(a=1e4),c.waitForTime(a)}),d.command.onEndDo(function(a){d.status=a,b.jobManager.terminateJob(c)}),d.command.execute(d.storage)},c},w=function(a,b){var c={};a=a||{},b=b||{};var d=[],e=a.name||"",f=a.announcer||{};return c.add=function(a){d.push(a)},c.remove=function(a){var b,c=[];for(b=0;b<d.length;b+=1)d[b]!==a&&c.push(d[b]);d=c},c.register=function(){f.register(c)},c.unregister=function(){f.unregister(c)},c.trigger=function(a){var b;for(b=0;b<d.length;b++)d[b].apply(null,a)},c},x=function(a,b){var c=function(a,b){var c={};a=a||{},b=b||{};var d={};return d.id=a.id||0,d.interval=400,d.interval_id=null,d.touch=function(){LocalOrCookieStorage.setItem("jio/id/"+d.id,Date.now())},c.setId=function(a){d.id=a},c.setIntervalDelay=function(a){d.interval=a},c.getIntervalDelay=function(){return d.interval},c.start=function(){d.interval_id||(d.touch(),d.interval_id=setInterval(function(){d.touch()},d.interval))},c.stop=function(){d.interval_id!==null&&(clearInterval(d.interval_id),d.interval_id=null)},c}(),d=function(a,b){var c={};a=a||{},b=b||{};var d={};return c.register=function(a){d[a]||(d[a]=w())},c.unregister=function(a){d[a]&&delete d[a]},c.at=function(a){return d[a]},c.on=function(a,b){c.register(a),c.at(a).add(b)},c.trigger=function(a,b){c.at(a).trigger(b)},c}(),e=function(a,b){var c={};a=a||{},b=b||{};var d=0;return c.nextId=function(){return d=d+1,d},c}(),f=function(a,b){var c={};a=a||{},b=b||{};var d="jio/job_array",f={};return f.id=a.id,f.interval_id=null,f.interval=200,f.job_array=[],b.jobManager=c,b.jobIdHandler=e,f.getJobArrayName=function(){return d+"/"+f.id},f.getJobArray=function(){return LocalOrCookieStorage.getItem(f.getJobArrayName())||[]},f.copyJobArrayToLocal=function(){var a=[],b;for(b=0;b<f.job_array.length;b+=1)a.push(f.job_array[b].serialized());LocalOrCookieStorage.setItem(f.getJobArrayName(),a)},f.removeJob=function(a){var b,c=[];for(b=0;b<f.job_array.length;b+=1)f.job_array[b]!==a&&c.push(f.job_array[b]);f.job_array=c,f.copyJobArrayToLocal()},c.setId=function(a){f.id=a},c.start=function(){var a;f.interval_id===null&&(f.interval_id=setInterval(function(){f.restoreOldJio();for(a=0;a<f.job_array.length;a+=1)c.execute(f.job_array[a])},f.interval))},c.stop=function(){f.interval_id!==null&&(clearInterval(f.interval_id),f.interval_id=null,f.job_array.length===0&&LocalOrCookieStorage.deleteItem(f.getJobArrayName()))},f.restoreOldJio=function(){var a,b;f.lastrestore=f.lastrestore||0;if(f.lastrestore>Date.now()-2e3)return;b=LocalOrCookieStorage.getItem("jio/id_array")||[];for(a=0;a<b.length;a+=1)f.restoreOldJioId(b[a]);f.lastrestore=Date.now()},f.restoreOldJioId=function(a){var b;b=LocalOrCookieStorage.getItem("jio/id/"+a)||0,(new Date(b)).getTime()<Date.now()-1e4&&(f.restoreOldJobFromJioId(a),f.removeOldJioId(a),f.removeJobArrayFromJioId(a))},f.restoreOldJobFromJioId=function(a){var d,e;e=LocalOrCookieStorage.getItem("jio/job_array/"+a)||[];for(d=0;d<e.length;d+=1){var f=j(e[d].command,b);f.canBeRestored()&&c.addJob(v({storage:y.storage(e[d].storage,b),command:f},b))}},f.removeOldJioId=function(a){var b,c,d=[];c=LocalOrCookieStorage.getItem("jio/id_array")||[];for(b=0;b<c.length;b+=1)c[b]!==a&&d.push(c[b]);LocalOrCookieStorage.setItem("jio/id_array",d),LocalOrCookieStorage.deleteItem("jio/id/"+a)},f.removeJobArrayFromJioId=function(a){LocalOrCookieStorage.deleteItem("jio/job_array/"+a)},c.execute=function(a){try{a.execute()}catch(b){switch(b.name){case"jobNotReadyException":break;case"tooMuchTriesJobException":break;default:throw b}}f.copyJobArrayToLocal()},c.jobIdExists=function(a){var b;for(b=0;b<f.job_array.length;b+=1)if(f.job_array[b].getId()===a)return!0;return!1},c.terminateJob=function(a){f.removeJob(a)},c.addJob=function(a){var b=c.validateJobAccordingToJobList(f.job_array,a);f.appendJob(a,b)},c.validateJobAccordingToJobList=function(a,b){var c,d=[];for(c=0;c<a.length;c+=1)d.push(g.validateJobAccordingToJob(a[c],b));return d},f.appendJob=function(a,b){var c;if(f.job_array.length!==b.length)throw new RangeError("Array out of bound");for(c=0;c<b.length;c+=1)if(b[c].action==="dont accept")return a.notAccepted();for(c=0;c<b.length;c+=1)switch(b[c].action){case"eliminate":b[c].job.eliminated(),f.removeJob(b[c].job);break;case"update":b[c].job.update(a),f.copyJobArrayToLocal();return;case"wait":a.waitForJob(b[c].job);break;default:}f.job_array.push(a),f.copyJobArrayToLocal()},c.serialized=function(){var a=[],b,c=f.job_array||[];for(b=0;b<c.length;b+=1)a.push(c[b].serialized());return a},c}(),g=function(a,b){var c={},d={};return d.compare={},d.action={},c.eliminate=function(){return"eliminate"},c.update=function(){return"update"},c.dontAccept=function(){return"dont accept"},c.wait=function(){return"wait"},c.none=function(){return"none"},c.default_action=c.none,c.default_compare=function(a,b){return a.getCommand().getDocId()===b.getCommand().getDocId()&&a.getCommand().getDocInfo("_rev")===b.getCommand().getDocInfo("_rev")&&a.getCommand().getOption("rev")===b.getCommand().getOption("rev")&&JSON.stringify(a.getStorage().serialized())===JSON.stringify(b.getStorage().serialized())},d.getAction=function(a,b){var e,f,g;return e=a.getCommand().getLabel(),f=b.getCommand().getLabel(),g=a.getStatus().getLabel()==="on going"?"on going":"not on going",d.action[e]&&d.action[e][g]&&d.action[e][g][f]?d.action[e][g][f](a,b):c.default_action(a,b)},d.canCompare=function(a,b){var e=a.getCommand().getLabel(),f=b.getCommand().getLabel();return d.compare[e]&&d.compare[f]?d.compare[e][f](a,b):c.default_compare(a,b)},c.validateJobAccordingToJob=function(a,b){return d.canCompare(a,b)?{action:d.getAction(a,b),job:a}:{action:c.default_action(a,b),job:a}},c.addActionRule=function(a,b,c,e){var f=b?"on going":"not on going";d.action[a]=d.action[a]||{},d.action[a][f]=d.action[a][f]||{},d.action[a][f][c]=e},c.addCompareRule=function(a,b,c){d.compare[a]=d.compare[a]||{},d.compare[a][b]=c},c.addActionRule("put",!0,"put",function(a,b){return a.getCommand().getDocInfo("content")===b.getCommand().getDocInfo("content")?c.dontAccept():c.wait()}),c.addActionRule("put",!0,"get",c.wait),c.addActionRule("put",!0,"remove",c.wait),c.addActionRule("put",!1,"put",c.update),c.addActionRule("put",!1,"get",c.wait),c.addActionRule("put",!1,"remove",c.eliminate),c.addActionRule("get",!0,"put",c.wait),c.addActionRule("get",!0,"get",c.dontAccept),c.addActionRule("get",!0,"remove",c.wait),c.addActionRule("get",!1,"put",c.wait),c.addActionRule("get",!1,"get",c.update),c.addActionRule("get",!1,"remove",c.wait),c.addActionRule("remove",!0,"get",c.dontAccept),c.addActionRule("remove",!0,"remove",c.dontAccept),c.addActionRule("remove",!1,"put",c.eliminate),c.addActionRule("remove",!1,"get",c.dontAccept),c.addActionRule("remove",!1,"remove",c.update),c.addActionRule("allDocs",!0,"allDocs",c.dontAccept),c.addActionRule("allDocs",!1,"allDocs",c.update),c}(),h={};a=a||{},b=b||{};var i={},o="jio/id_array";return i.id=null,b.jobManager=f,b.jobIdHandler=e,i.storage_spec=a,i.init=function(){if(i.id===null){var a,b=LocalOrCookieStorage.getItem(o)||[];i.id=1;for(a=0;a<b.length;a+=1)b[a]>=i.id&&(i.id=b[a]+1);b.push(i.id),LocalOrCookieStorage.setItem(o,b),c.setId(i.id),f.setId(i.id)}},h.start=function(){i.init(),c.start(),f.start()},h.stop=function(){f.stop()},h.close=function(){c.stop(),f.stop(),i.id=null},h.start(),h.getId=function(){return i.id},h.getJobRules=function(){return g},h.validateStorageDescription=function(a){return y.storage(a,b).isValid()},h.getJobArray=function(){return f.serialized()},i.getParam=function(a,b){var c={},d=0;return b||(c.doc=a[d],d++),typeof a[d]=="object"?(c.options=a[d],d++):c.options={},c.callback=function(a,b){},c.success=function(a){c.callback(undefined,a)},c.error=function(a){c.callback(a,undefined)},typeof a[d]=="function"&&(typeof a[d+1]=="function"?(c.success=a[d],c.error=a[d+1]):c.callback=a[d]),c},i.addJob=function(a,c){f.addJob(v({storage:y.storage(i.storage_spec,b),command:a(c,b)},b))},h.put=function(){var a=i.getParam(arguments);a.options.max_retry=a.options.max_retry||0,i.addJob(n,{doc:a.doc,options:a.options,callbacks:{success:a.success,error:a.error}})},h.get=function(){var a=i.getParam(arguments);a.options.max_retry=a.options.max_retry||3,a.options.metadata_only=a.options.metadata_only!==undefined?a.options.metadata_only:!1,i.addJob(l,{docid:a.doc,options:a.options,callbacks:{success:a.success,error:a.error}})},h.remove=function(){var a=i.getParam(arguments);a.options.max_retry=a.options.max_retry||0,i.addJob(m,{doc:a.doc,options:a.options,callbacks:{success:a.success,error:a.error}})},h.allDocs=function(){var a=i.getParam(arguments,"no doc");a.options.max_retry=a.options.max_retry||3,a.options.metadata_only=a.options.metadata_only!==undefined?a.options.metadata_only:!0,i.addJob(k,{options:a.options,callbacks:{success:a.success,error:a.error}})},h},y=function(a,b){var c={};a=a||{},b=b||{};var e={base:h,handler:i};return c.storage=function(a,b,c){a=a||{},b=b||{};var f=c||a.type||"base";if(!e[f])throw d({type:f,message:"Storage does not exists."});return e[f](a,b)},c.newJio=function(a){var b=a;return typeof b=="string"&&(b=JSON.parse(b)),b=b||{type:"base"},x(a)},c.addStorageType=function(a,b){b=b||function(){return null};if(e[a])throw d({type:a,message:"Already known."});e[a]=b},c}();return y}();
\ No newline at end of file
var allDocsCommand = function(spec, my) {
var that = command(spec, my);
spec = spec || {};
my = my || {};
// Attributes //
// Methods //
that.getLabel = function() {
return 'allDocs';
};
that.executeOn = function(storage) {
storage.allDocs (that);
};
that.canBeRestored = function() {
return false;
};
return that;
};
......@@ -4,10 +4,11 @@ var command = function(spec, my) {
my = my || {};
// Attributes //
var priv = {};
priv.commandlist = {'saveDocument':saveDocument,
'loadDocument':loadDocument,
'removeDocument':removeDocument,
'getDocumentList':getDocumentList};
priv.commandlist = {'post':postCommand,
'put':putCommand,
'get':getCommand,
'remove':removeCommand,
'allDocs':allDocsCommand};
// creates the good command thanks to his label
if (spec.label && priv.commandlist[spec.label]) {
priv.label = spec.label;
......@@ -15,14 +16,18 @@ var command = function(spec, my) {
return priv.commandlist[priv.label](spec, my);
}
priv.path = spec.path || '';
priv.tried = 0;
priv.option = spec.option || {};
priv.success = priv.option.success || function (){};
priv.error = priv.option.error || function (){};
priv.doc = spec.doc || {};
priv.docid = spec.docid || '';
priv.option = spec.options || {};
priv.callbacks = spec.callbacks || {};
priv.success = priv.callbacks.success || function (){};
priv.error = priv.callbacks.error || function (){};
priv.retry = function() {
that.error({status:13,statusText:'Fail Retry',
message:'Impossible to retry.'});
that.error({
status:13,statusText:'Fail Retry',error:'fail_retry',
message:'Impossible to retry.',reason:'Impossible to retry.'
});
};
priv.end = function() {};
priv.on_going = false;
......@@ -37,8 +42,7 @@ var command = function(spec, my) {
that.serialized = function() {
return {label:that.getLabel(),
tried:priv.tried,
max_retry:priv.max_retry,
path:priv.path,
doc:that.cloneDoc(),
option:that.cloneOption()};
};
......@@ -51,13 +55,21 @@ var command = function(spec, my) {
return 'command';
};
that.getDocId = function () {
return priv.docid || priv.doc._id;
};
that.getDocContent = function () {
return priv.doc.content;
};
/**
* Returns the path of the command.
* @method getPath
* @return {string} The path of the command.
* Returns an information about the document.
* @method getDocInfo
* @param {string} infoname The info name.
* @return The info value.
*/
that.getPath = function() {
return priv.path;
that.getDocInfo = function (infoname) {
return priv.doc[infoname];
};
/**
......@@ -66,38 +78,56 @@ var command = function(spec, my) {
* @param {string} optionname The option name.
* @return The option value.
*/
that.getOption = function(optionname) {
that.getOption = function (optionname) {
return priv.option[optionname];
};
/**
* Validates the storage.
* Override this function.
* @param {object} handler The storage handler
* @param {object} storage The storage.
*/
that.validate = function (storage) {
if (!that.validateState()) { return false; }
return storage.validate();
};
/*
* Extend this function
*/
that.validate = function(handler) {
that.validateState();
that.validateState = function() {
if (typeof priv.doc !== 'object') {
that.error({
status:20,
statusText:'Document_Id Required',
error:'document_id_required',
message:'No document id.',
reason:'no document id'
});
return false;
}
return true;
};
that.canBeRetried = function () {
return (priv.option.max_retry === 0 ||
return (typeof priv.option.max_retry === 'undefined' ||
priv.option.max_retry === 0 ||
priv.tried < priv.option.max_retry);
};
that.getTried = function() {
return priv.tried;
};
/**
* Delegate actual excecution the storage handler.
* @param {object} handler The storage handler.
* Delegate actual excecution the storage.
* @param {object} storage The storage.
*/
that.execute = function(handler) {
that.execute = function(storage) {
if (!priv.on_going) {
that.validate(handler);
priv.tried ++;
priv.on_going = true;
handler.execute(that);
if (that.validate (storage)) {
priv.tried ++;
priv.on_going = true;
storage.execute (that);
}
}
};
......@@ -109,16 +139,6 @@ var command = function(spec, my) {
*/
that.executeOn = function(storage) {};
/*
* Do not override.
* Override `validate()' instead
*/
that.validateState = function() {
if (priv.path === '') {
throw invalidCommandState({command:that,message:'Path is empty'});
}
};
that.success = function(return_value) {
priv.on_going = false;
priv.success (return_value);
......@@ -199,5 +219,21 @@ var command = function(spec, my) {
return o;
};
/**
* Clones the document and returns the clone version.
* @method cloneDoc
* @return {object} The clone of the document.
*/
that.cloneDoc = function () {
if (priv.docid) {
return priv.docid;
}
var k, o = {};
for (k in priv.doc) {
o[k] = priv.doc[k];
}
return o;
};
return that;
};
var loadDocument = function(spec, my) {
var getCommand = function(spec, my) {
var that = command(spec, my);
spec = spec || {};
my = my || {};
// Attributes //
// Methods //
that.getLabel = function() {
return 'loadDocument';
return 'get';
};
that.validateState = function() {
if (!that.getDocId()) {
that.error({
status:20,statusText:'Document Id Required',
error:'document_id_required',
message:'No document id.',reason:'no document id'
});
return false;
}
return true;
};
that.executeOn = function(storage) {
storage.loadDocument(that);
storage.get (that);
};
that.canBeRestored = function() {
return false;
};
var super_success = that.success;
that.success = function (res) {
if (res) {
if (typeof res.last_modified !== 'number') {
res.last_modified=new Date(res.last_modified).getTime();
}
if (typeof res.creation_date !== 'number') {
res.creation_date=new Date(res.creation_date).getTime();
}
}
super_success(res);
};
return that;
};
var getDocumentList = function(spec, my) {
var that = command(spec, my);
spec = spec || {};
my = my || {};
// Attributes //
// Methods //
that.getLabel = function() {
return 'getDocumentList';
};
that.executeOn = function(storage) {
storage.getDocumentList(that);
};
that.canBeRestored = function() {
return false;
};
var super_success = that.success;
that.success = function (res) {
var i;
if (res) {
for (i = 0; i < res.length; i+= 1) {
if (typeof res[i].last_modified !== 'number') {
res[i].last_modified =
new Date(res[i].last_modified).getTime();
}
if (typeof res[i].creation_date !== 'number') {
res[i].creation_date =
new Date(res[i].creation_date).getTime();
}
}
}
super_success(res);
};
return that;
};
var saveDocument = function(spec, my) {
var postCommand = function(spec, my) {
var that = command(spec, my);
spec = spec || {};
my = my || {};
// Attributes //
var priv = {};
priv.content = spec.content;
// Methods //
that.getLabel = function() {
return 'saveDocument';
};
that.getContent = function() {
return priv.content;
return 'post';
};
/**
* Validates the storage handler.
* @param {object} handler The storage handler
*/
var super_validate = that.validate;
that.validate = function(handler) {
if (typeof priv.content !== 'string') {
throw invalidCommandState({command:that,message:'No data to save'});
var super_validateState = that.validateState;
that.validate = function () {
if (typeof that.getDocInfo('content') !== 'string') {
that.error({
status:21,statusText:'Content Required',
error:'content_required',
message:'No data to put.',reason:'no data to put'
});
return false;
}
super_validate(handler);
return super_validateState();
};
that.executeOn = function(storage) {
storage.saveDocument(that);
};
var super_serialized = that.serialized;
that.serialized = function() {
var o = super_serialized();
o.content = priv.content;
return o;
storage.put (that);
};
return that;
......
var putCommand = function(spec, my) {
var that = command(spec, my);
spec = spec || {};
my = my || {};
// Attributes //
var priv = {};
// Methods //
that.getLabel = function() {
return 'put';
};
/**
* Validates the storage handler.
* @param {object} handler The storage handler
*/
var super_validateState = that.validateState;
that.validate = function () {
if (typeof that.getDocInfo('content') !== 'string') {
that.error({
status:21,statusText:'Content Required',
error:'content_required',
message:'No data to put.',reason:'no data to put'
});
return false;
}
return super_validateState();
};
that.executeOn = function(storage) {
storage.put (that);
};
return that;
};
var removeDocument = function(spec, my) {
var removeCommand = function(spec, my) {
var that = command(spec, my);
spec = spec || {};
my = my || {};
// Attributes //
// Methods //
that.getLabel = function() {
return 'removeDocument';
return 'remove';
};
that.executeOn = function(storage) {
storage.removeDocument(that);
storage.remove (that);
};
return that;
......
......@@ -78,107 +78,168 @@
return jobManager.serialized();
};
priv.getParam = function (list,nodoc) {
var param = {}, i = 0;
if (!nodoc) {
param.doc = list[i];
i ++;
}
if (typeof list[i] === 'object') {
param.options = list[i];
i ++;
} else {
param.options = {};
}
param.callback = function (err,val){};
param.success = function (val) {
param.callback(undefined,val);
};
param.error = function (err) {
param.callback(err,undefined);
};
if (typeof list[i] === 'function') {
if (typeof list[i+1] === 'function') {
param.success = list[i];
param.error = list[i+1];
} else {
param.callback = list[i];
}
}
return param;
};
priv.addJob = function (commandCreator,spec) {
jobManager.addJob(
job({storage:jioNamespace.storage(priv.storage_spec,my),
command:commandCreator(spec,my)},my));
};
// /**
// * Post a document.
// * @method post
// * @param {object} doc The document {"content":}.
// * @param {object} options (optional) Contains some options:
// * - {number} max_retry The number max of retries, 0 = infinity.
// * - {boolean} revs Include revision history of the document.
// * - {boolean} revs_info Retreive the revisions.
// * - {boolean} conflicts Retreive the conflict list.
// * @param {function} callback (optional) The callback(err,response).
// * @param {function} error (optional) The callback on error, if this
// * callback is given in parameter, "callback" is changed as "success",
// * called on success.
// */
// that.post = function() {
// var param = priv.getParam(arguments);
// param.options.max_retry = param.options.max_retry || 0;
// priv.addJob(postCommand,{
// doc:param.doc,
// options:param.options,
// callbacks:{success:param.success,error:param.error}
// });
// };
/**
* Save a document.
* @method saveDocument
* @param {string} path The document path name.
* @param {string} content The document's content.
* @param {object} option (optional) Contains some options:
* - {function} success The callback called when the job has passed.
* - {function} error The callback called when the job has fail.
* Put a document.
* @method put
* @param {object} doc The document {"_id":,"_rev":,"content":}.
* @param {object} options (optional) Contains some options:
* - {number} max_retry The number max of retries, 0 = infinity.
* @param {object} specificstorage (optional) A specific storage, only if
* you want to save this document elsewhere.
* - {boolean} revs Include revision history of the document.
* - {boolean} revs_info Retreive the revisions.
* - {boolean} conflicts Retreive the conflict list.
* @param {function} callback (optional) The callback(err,response).
* @param {function} error (optional) The callback on error, if this
* callback is given in parameter, "callback" is changed as "success",
* called on success.
*/
that.saveDocument = function(path, content, option, specificstorage) {
option = option || {};
option.success = option.success || function(){};
option.error = option.error || function(){};
option.max_retry = option.max_retry || 0;
jobManager.addJob(
job({storage:(specificstorage?
jioNamespace.storage(specificstorage,my):
jioNamespace.storage(priv.storage_spec,my)),
command:saveDocument(
{path:path,content:content,option:option},my)},my));
that.put = function() {
var param = priv.getParam(arguments);
param.options.max_retry = param.options.max_retry || 0;
priv.addJob(putCommand,{
doc:param.doc,
options:param.options,
callbacks:{success:param.success,error:param.error}
});
};
/**
* Load a document.
* @method loadDocument
* @param {string} path The document path name.
* @param {object} option (optional) Contains some options:
* - {function} success The callback called when the job has passed.
* - {function} error The callback called when the job has fail.
* Get a document.
* @method get
* @param {string} docid The document id (the path).
* @param {object} options (optional) Contains some options:
* - {number} max_retry The number max of retries, 0 = infinity.
* - {boolean} metadata_only Load only document metadata.
* @param {object} specificstorage (optional) A specific storage, only if
* you want to save this document elsewhere.
* - {string} rev The revision we want to get.
* - {boolean} revs Include revision history of the document.
* - {boolean} revs_info Include list of revisions, and their availability.
* - {boolean} conflicts Include a list of conflicts.
* @param {function} callback (optional) The callback(err,response).
* @param {function} error (optional) The callback on error, if this
* callback is given in parameter, "callback" is changed as "success",
* called on success.
*/
that.loadDocument = function(path, option, specificstorage) {
option = option || {};
option.success = option.success || function(){};
option.error = option.error || function(){};
option.max_retry = option.max_retry || 3;
option.metadata_only = (option.metadata_only !== undefined?
option.metadata_only:false);
jobManager.addJob(
job({storage:(specificstorage?
jioNamespace.storage(specificstorage,my):
jioNamespace.storage(priv.storage_spec,my)),
command:loadDocument(
{path:path,option:option},my)},my));
that.get = function() {
var param = priv.getParam(arguments);
param.options.max_retry = param.options.max_retry || 3;
param.options.metadata_only = (
param.options.metadata_only !== undefined?
param.options.metadata_only:false);
priv.addJob(getCommand,{
docid:param.doc,
options:param.options,
callbacks:{success:param.success,error:param.error}
});
};
/**
* Remove a document.
* @method removeDocument
* @param {string} path The document path name.
* @param {object} option (optional) Contains some options:
* - {function} success The callback called when the job has passed.
* - {function} error The callback called when the job has fail.
* @method remove
* @param {object} doc The document {"_id":,"_rev":}.
* @param {object} options (optional) Contains some options:
* - {number} max_retry The number max of retries, 0 = infinity.
* @param {object} specificstorage (optional) A specific storage, only if
* you want to save this document elsewhere.
* - {boolean} revs Include revision history of the document.
* - {boolean} revs_info Include list of revisions, and their availability.
* - {boolean} conflicts Include a list of conflicts.
* @param {function} callback (optional) The callback(err,response).
* @param {function} error (optional) The callback on error, if this
* callback is given in parameter, "callback" is changed as "success",
* called on success.
*/
that.removeDocument = function(path, option, specificstorage) {
option = option || {};
option.success = option.success || function(){};
option.error = option.error || function(){};
option.max_retry = option.max_retry || 0;
jobManager.addJob(
job({storage:(specificstorage?
jioNamespace.storage(specificstorage,my):
jioNamespace.storage(priv.storage_spec,my)),
command:removeDocument(
{path:path,option:option},my)},my));
that.remove = function() {
var param = priv.getParam(arguments);
param.options.max_retry = param.options.max_retry || 0;
priv.addJob(removeCommand,{
doc:param.doc,
options:param.options,
callbacks:{success:param.success,error:param.error}
});
};
/**
* Get a document list from a folder.
* @method getDocumentList
* @param {string} path The folder path.
* @param {object} option (optional) Contains some options:
* - {function} success The callback called when the job has passed.
* - {function} error The callback called when the job has fail.
* Get a list of documents.
* @method allDocs
* @param {object} options (optional) Contains some options:
* - {number} max_retry The number max of retries, 0 = infinity.
* - {boolean} metadata_only Load only document metadata
* @param {object} specificstorage (optional) A specific storage, only if
* you want to save this document elsewhere.
* - {boolean} descending Reverse the order of the output table.
* - {boolean} revs Include revision history of the document.
* - {boolean} revs_info Include revisions.
* - {boolean} conflicts Include conflicts.
* @param {function} callback (optional) The callback(err,response).
* @param {function} error (optional) The callback on error, if this
* callback is given in parameter, "callback" is changed as "success",
* called on success.
*/
that.getDocumentList = function(path, option, specificstorage) {
option = option || {};
option.success = option.success || function(){};
option.error = option.error || function(){};
option.max_retry = option.max_retry || 3;
option.metadata_only = (option.metadata_only !== undefined?
option.metadata_only:true);
jobManager.addJob(
job({storage:(specificstorage?
jioNamespace.storage(specificstorage,my):
jioNamespace.storage(priv.storage_spec,my)),
command:getDocumentList(
{path:path,option:option},my)},my));
that.allDocs = function() {
var param = priv.getParam(arguments,'no doc');
param.options.max_retry = param.options.max_retry || 3;
param.options.metadata_only = (
param.options.metadata_only !== undefined?
param.options.metadata_only:true);
priv.addJob(allDocsCommand,{
options:param.options,
callbacks:{success:param.success,error:param.error}
});
};
return that;
......
......@@ -49,7 +49,7 @@ var job = function(spec, my) {
* @return {boolean} true if ready, else false.
*/
that.isReady = function() {
if (that.getCommand().getTried() === 0) {
if (priv.command.getTried() === 0) {
return priv.status.canStart();
} else {
return priv.status.canRestart();
......@@ -116,8 +116,9 @@ var job = function(spec, my) {
that.eliminated = function () {
priv.command.error ({
status:10,statusText:'Stoped',
message:'This job has been stoped by another one.'});
status:10,statusText:'Stopped',error:'stopped',
message:'This job has been stoped by another one.',
reason:this.message});
};
that.notAccepted = function () {
......@@ -125,8 +126,9 @@ var job = function(spec, my) {
priv.status = failStatus();
my.jobManager.terminateJob (that);
});
priv.command.error ({status:11,statusText:'Not Accepted',
message:'This job is already running.'});
priv.command.error ({
status:11,statusText:'Not Accepted',error:'not_accepted',
message:'This job is already running.',reason:this.message});
};
/**
......@@ -135,13 +137,19 @@ var job = function(spec, my) {
* @param {object} job The other job.
*/
that.update = function(job) {
priv.command.error ({status:12,statusText:'Replaced',
message:'Job has been replaced by another one.'});
priv.date = job.getDate();
priv.command.error ({
status:12,statusText:'Replaced',error:'replaced',
message:'Job has been replaced by another one.',
reason:'job has been replaced by another one'});
priv.date = new Date(job.getDate().getTime());
priv.command = job.getCommand();
priv.status = job.getStatus();
};
/**
* Executes this job.
* @method execute
*/
that.execute = function() {
if (!that.getCommand().canBeRetried()) {
throw tooMuchTriesJobException(
......
......@@ -124,7 +124,7 @@ var jobManager = (function(spec, my) {
priv.restoreOldJioId = function(id) {
var jio_date;
jio_date = LocalOrCookieStorage.getItem('jio/id/'+id)||0;
if (jio_date < (Date.now() - 10000)) { // 10 sec
if (new Date(jio_date).getTime() < (Date.now() - 10000)) { // 10 sec
priv.restoreOldJobFromJioId(id);
priv.removeOldJioId(id);
priv.removeJobArrayFromJioId(id);
......@@ -224,8 +224,8 @@ var jobManager = (function(spec, my) {
* @param {object} job The new job.
*/
that.addJob = function(job) {
var result_a = that.validateJobAccordingToJobList (priv.job_array,job);
priv.appendJob (job,result_a);
var result_array = that.validateJobAccordingToJobList (priv.job_array,job);
priv.appendJob (job,result_array);
};
/**
......@@ -236,11 +236,11 @@ var jobManager = (function(spec, my) {
* @return {array} A result array.
*/
that.validateJobAccordingToJobList = function(job_array,job) {
var i, result_a = [];
var i, result_array = [];
for (i = 0; i < job_array.length; i+= 1) {
result_a.push(jobRules.validateJobAccordingToJob (job_array[i],job));
result_array.push(jobRules.validateJobAccordingToJob (job_array[i],job));
}
return result_a;
return result_array;
};
/**
......@@ -250,30 +250,30 @@ var jobManager = (function(spec, my) {
* one, to replace one or to eliminate some while browsing.
* @method appendJob
* @param {object} job The job to append.
* @param {array} result_a The result array.
* @param {array} result_array The result array.
*/
priv.appendJob = function(job,result_a) {
priv.appendJob = function(job,result_array) {
var i;
if (priv.job_array.length !== result_a.length) {
if (priv.job_array.length !== result_array.length) {
throw new RangeError("Array out of bound");
}
for (i = 0; i < result_a.length; i+= 1) {
if (result_a[i].action === 'dont accept') {
for (i = 0; i < result_array.length; i+= 1) {
if (result_array[i].action === 'dont accept') {
return job.notAccepted();
}
}
for (i = 0; i < result_a.length; i+= 1) {
switch (result_a[i].action) {
for (i = 0; i < result_array.length; i+= 1) {
switch (result_array[i].action) {
case 'eliminate':
result_a[i].job.eliminated();
priv.removeJob(result_a[i].job);
result_array[i].job.eliminated();
priv.removeJob(result_array[i].job);
break;
case 'update':
result_a[i].job.update(job);
result_array[i].job.update(job);
priv.copyJobArrayToLocal();
return;
case 'wait':
job.waitForJob(result_a[i].job);
job.waitForJob(result_array[i].job);
break;
default: break;
}
......
......@@ -12,7 +12,12 @@ var jobRules = (function(spec, my) {
that.none = function() { return 'none'; };
that.default_action = that.none;
that.default_compare = function(job1,job2) {
return (job1.getCommand().getPath() === job2.getCommand().getPath() &&
return (job1.getCommand().getDocId() ===
job2.getCommand().getDocId() &&
job1.getCommand().getDocInfo('_rev') ===
job2.getCommand().getDocInfo('_rev') &&
job1.getCommand().getOption('rev') ===
job2.getCommand().getOption('rev') &&
JSON.stringify(job1.getStorage().serialized()) ===
JSON.stringify(job2.getStorage().serialized()));
};
......@@ -152,36 +157,36 @@ var jobRules = (function(spec, my) {
For more information, see documentation
*/
that.addActionRule ('saveDocument',true,'saveDocument',
function(job1,job2){
if (job1.getCommand().getContent() ===
job2.getCommand().getContent()) {
return that.dontAccept();
} else {
return that.wait();
}
});
that.addActionRule('saveDocument' ,true ,'loadDocument' ,that.wait);
that.addActionRule('saveDocument' ,true ,'removeDocument' ,that.wait);
that.addActionRule('saveDocument' ,false,'saveDocument' ,that.update);
that.addActionRule('saveDocument' ,false,'loadDocument' ,that.wait);
that.addActionRule('saveDocument' ,false,'removeDocument' ,that.eliminate);
that.addActionRule ('put' ,true,'put',
function(job1,job2){
if (job1.getCommand().getDocInfo('content') ===
job2.getCommand().getDocInfo('content')) {
return that.dontAccept();
} else {
return that.wait();
}
});
that.addActionRule('put' ,true ,'get' ,that.wait);
that.addActionRule('put' ,true ,'remove' ,that.wait);
that.addActionRule('put' ,false,'put' ,that.update);
that.addActionRule('put' ,false,'get' ,that.wait);
that.addActionRule('put' ,false,'remove' ,that.eliminate);
that.addActionRule('loadDocument' ,true ,'saveDocument' ,that.wait);
that.addActionRule('loadDocument' ,true ,'loadDocument' ,that.dontAccept);
that.addActionRule('loadDocument' ,true ,'removeDocument' ,that.wait);
that.addActionRule('loadDocument' ,false,'saveDocument' ,that.wait);
that.addActionRule('loadDocument' ,false,'loadDocument' ,that.update);
that.addActionRule('loadDocument' ,false,'removeDocument' ,that.wait);
that.addActionRule('get' ,true ,'put' ,that.wait);
that.addActionRule('get' ,true ,'get' ,that.dontAccept);
that.addActionRule('get' ,true ,'remove' ,that.wait);
that.addActionRule('get' ,false,'put' ,that.wait);
that.addActionRule('get' ,false,'get' ,that.update);
that.addActionRule('get' ,false,'remove' ,that.wait);
that.addActionRule('removeDocument' ,true ,'loadDocument' ,that.dontAccept);
that.addActionRule('removeDocument' ,true ,'removeDocument' ,that.dontAccept);
that.addActionRule('removeDocument' ,false,'saveDocument' ,that.eliminate);
that.addActionRule('removeDocument' ,false,'loadDocument' ,that.dontAccept);
that.addActionRule('removeDocument' ,false,'removeDocument' ,that.update);
that.addActionRule('remove' ,true ,'get' ,that.dontAccept);
that.addActionRule('remove' ,true ,'remove' ,that.dontAccept);
that.addActionRule('remove' ,false,'put' ,that.eliminate);
that.addActionRule('remove' ,false,'get' ,that.dontAccept);
that.addActionRule('remove' ,false,'remove' ,that.update);
that.addActionRule('getDocumentList',true ,'getDocumentList',that.dontAccept);
that.addActionRule('getDocumentList',false,'getDocumentList',that.update);
that.addActionRule('allDocs',true ,'allDocs',that.dontAccept);
that.addActionRule('allDocs',false,'allDocs',that.update);
// end adding rules
////////////////////////////////////////////////////////////////////////////
return that;
......
......@@ -20,12 +20,13 @@ var storage = function(spec, my) {
* @param {object} command The command
*/
that.execute = function(command) {
that.validate(command);
that.success = command.success;
that.error = command.error;
that.retry = command.retry;
that.end = command.end;
command.executeOn(that);
if (that.validate(command)) {
command.executeOn(that);
}
};
/**
......@@ -37,12 +38,15 @@ var storage = function(spec, my) {
return true;
};
that.validate = function(command) {
that.validate = function () {
var mess = that.validateState();
if (mess) {
throw invalidStorage({storage:that,message:mess});
that.error({status:0,statusText:'Invalid Storage',
error:'invalid_storage',
message:mess,reason:mess});
return false;
}
command.validate(that);
return true;
};
/**
......@@ -55,7 +59,8 @@ var storage = function(spec, my) {
};
that.saveDocument = function(command) {
throw invalidStorage({storage:that,message:'Unknown storage.'});
that.error({status:0,statusText:'Unknown storage',
error:'unknown_storage',message:'Unknown Storage'});
};
that.loadDocument = function(command) {
that.saveDocument();
......
var storageHandler = function(spec, my) {
spec = spec || {};
my = my || {};
var that = storage( spec, my );
var that = storage( spec, my ), priv = {};
that.newCommand = function (method, spec) {
priv.newCommand = function (method, spec) {
var o = spec || {};
o.label = method;
return command (o, my);
};
that.newStorage = function (spec) {
var o = spec || {};
return jioNamespace.storage (o, my);
};
that.addJob = function (storage,command) {
my.jobManager.addJob ( job({storage:storage, command:command}, my) );
that.addJob = function (method,storage_spec,doc,option,success,error) {
var command_opt = {
options: option,
callbacks:{success:success,error:error}
};
if (doc) {
if (method === 'get') {
command_opt.docid = doc;
} else {
command_opt.doc = doc;
}
}
my.jobManager.addJob (
job({
storage:jioNamespace.storage(storage_spec||{}),
command:priv.newCommand(method,command_opt)
}, my)
);
};
return that;
......
......@@ -14,27 +14,6 @@
<script type="text/javascript" src="./testlocalorcookiestorage.js"></script>
<script type="text/javascript" src="../lib/jio/jio.js"></script>
<script type="text/javascript" src="../src/jio/activityUpdater.js"></script>
<script type="text/javascript" src="../src/jio/announcements/announcement.js"></script>
<script type="text/javascript" src="../src/jio/announcements/announcer.js"></script>
<script type="text/javascript" src="../src/jio/commands/command.js"></script>
<script type="text/javascript" src="../src/jio/commands/getDocumentList.js"></script>
<script type="text/javascript" src="../src/jio/commands/loadDocument.js"></script>
<script type="text/javascript" src="../src/jio/commands/removeDocument.js"></script>
<script type="text/javascript" src="../src/jio/commands/saveDocument.js"></script>
<script type="text/javascript" src="../src/jio/exceptions.js"></script>
<script type="text/javascript" src="../src/jio/jobs/jobIdHandler.js"></script>
<script type="text/javascript" src="../src/jio/jobs/job.js"></script>
<script type="text/javascript" src="../src/jio/jobs/jobManager.js"></script>
<script type="text/javascript" src="../src/jio/jobs/jobRules.js"></script>
<script type="text/javascript" src="../src/jio/jobs/status/doneStatus.js"></script>
<script type="text/javascript" src="../src/jio/jobs/status/failStatus.js"></script>
<script type="text/javascript" src="../src/jio/jobs/status/initialStatus.js"></script>
<script type="text/javascript" src="../src/jio/jobs/status/jobStatus.js"></script>
<script type="text/javascript" src="../src/jio/jobs/status/onGoingStatus.js"></script>
<script type="text/javascript" src="../src/jio/jobs/status/waitStatus.js"></script>
<script type="text/javascript" src="../src/jio/storages/storageHandler.js"></script>
<script type="text/javascript" src="../src/jio/storages/storage.js"></script>
<script type="text/javascript" src="../lib/base64/base64.js"></script>
<script type="text/javascript" src="../lib/sjcl/sjcl.min.js"></script>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment