Commit d74b545d authored by Aurel's avatar Aurel

make distributable package for clearroad on nodejs

parent 46a642ae
......@@ -209,7 +209,7 @@ module.exports = function (grunt) {
'src/jio.storage/localstorage.js',
'src/jio.storage/mappingstorage.js'
],
dest: 'dist/nodejs/<%= pkg.name %>-<%= pkg.version %>.js'
dest: 'nodejs/lib/jio/<%= pkg.name %>-<%= pkg.version %>.js'
// dest: 'jio.js'
}
},
......@@ -238,7 +238,7 @@ module.exports = function (grunt) {
},
nodejs: {
src: "<%= concat.nodejs.dest %>",
dest: "dist/nodejs/<%= pkg.name %>-<%= pkg.version %>.min.js"
dest: "nodejs/lib/jio/<%= pkg.name %>-<%= pkg.version %>.min.js"
}
},
......@@ -252,10 +252,10 @@ module.exports = function (grunt) {
dest: "dist/<%= pkg.name %>-latest.min.js"
}, {
src: '<%= uglify.nodejs.src %>',
dest: "dist/nodejs/<%= pkg.name %>-latest.js"
dest: "nodejs/lib/jio/<%= pkg.name %>.js"
}, {
src: '<%= uglify.nodejs.dest %>',
dest: "dist/nodejs/<%= pkg.name %>-latest.min.js"
dest: "nodejs/lib/jio/<%= pkg.name %>.min.js"
}]
}
},
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"name": "clearroad",
"version": "1.0.0",
"description": "ClearRoad Lib based on JIO",
"main": "clearroad.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "lab.nexedi.com/nexedi/jio"
},
"keywords": [
"clearroad",
"jio"
],
"author": "Aurélien Calonne",
"license": "ISC"
}
{
"name": "html5",
"version": "1.0.0",
"description": "",
"main": "html5.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
......@@ -1891,7 +1891,7 @@ return new Parser;
};
}(window, moment));
;/*global window, RSVP, Blob, XMLHttpRequest, QueryFactory, Query, atob,
FileReader, ArrayBuffer, Uint8Array, navigator */
FileReader, ArrayBuffer, Uint8Array, navigator, FormData, StreamBuffers */
(function (window, RSVP, Blob, QueryFactory, Query, atob,
FileReader, ArrayBuffer, Uint8Array, navigator) {
"use strict";
......@@ -1934,7 +1934,7 @@ return new Parser;
function ajax(param) {
var xhr = new XMLHttpRequest();
return new RSVP.Promise(function (resolve, reject, notify) {
var k;
var k, buffer = new StreamBuffers.WritableStreamBuffer();
xhr.open(param.type || "GET", param.url, true);
xhr.responseType = param.dataType || "";
if (typeof param.headers === 'object' && param.headers !== null) {
......@@ -1944,6 +1944,7 @@ return new Parser;
}
}
}
xhr.setRequestHeader("Accept", "*/*");
xhr.addEventListener("load", function (e) {
if (e.target.status >= 400) {
return reject(e);
......@@ -1962,7 +1963,14 @@ return new Parser;
if (typeof param.beforeSend === 'function') {
param.beforeSend(xhr);
}
xhr.send(param.data);
if (param.data instanceof FormData) {
xhr.setRequestHeader("Content-Type",
"multipart\/form-data; boundary=" + param.data.getBoundary());
param.data.pipe(buffer);
xhr.send(buffer.getContents());
} else {
xhr.send(param.data);
}
}, function () {
xhr.abort();
});
......@@ -3495,6 +3503,176 @@ return new Parser;
jIO.addStorage('uuid', UUIDStorage);
}(jIO));
;/*
* Copyright 2013, Nexedi SA
* Released under the LGPL license.
* http://www.gnu.org/licenses/lgpl.html
*/
/*jslint nomen: true*/
/*global jIO, RSVP*/
/**
* JIO Memory Storage. Type = 'memory'.
* Memory browser "database" storage.
*
* Storage Description:
*
* {
* "type": "memory"
* }
*
* @class MemoryStorage
*/
(function (jIO, JSON, RSVP) {
"use strict";
/**
* The JIO MemoryStorage extension
*
* @class MemoryStorage
* @constructor
*/
function MemoryStorage() {
this._database = {};
}
MemoryStorage.prototype.put = function (id, metadata) {
if (!this._database.hasOwnProperty(id)) {
this._database[id] = {
attachments: {}
};
}
this._database[id].doc = JSON.stringify(metadata);
return id;
};
MemoryStorage.prototype.get = function (id) {
try {
return JSON.parse(this._database[id].doc);
} catch (error) {
if (error instanceof TypeError) {
throw new jIO.util.jIOError(
"Cannot find document: " + id,
404
);
}
throw error;
}
};
MemoryStorage.prototype.allAttachments = function (id) {
var key,
attachments = {};
try {
for (key in this._database[id].attachments) {
if (this._database[id].attachments.hasOwnProperty(key)) {
attachments[key] = {};
}
}
} catch (error) {
if (error instanceof TypeError) {
throw new jIO.util.jIOError(
"Cannot find document: " + id,
404
);
}
throw error;
}
return attachments;
};
MemoryStorage.prototype.remove = function (id) {
delete this._database[id];
return id;
};
MemoryStorage.prototype.getAttachment = function (id, name) {
try {
var result = this._database[id].attachments[name];
if (result === undefined) {
throw new jIO.util.jIOError(
"Cannot find attachment: " + id + " , " + name,
404
);
}
return jIO.util.dataURItoBlob(result);
} catch (error) {
if (error instanceof TypeError) {
throw new jIO.util.jIOError(
"Cannot find attachment: " + id + " , " + name,
404
);
}
throw error;
}
};
MemoryStorage.prototype.putAttachment = function (id, name, blob) {
var attachment_dict;
try {
attachment_dict = this._database[id].attachments;
} catch (error) {
if (error instanceof TypeError) {
throw new jIO.util.jIOError("Cannot find document: " + id, 404);
}
throw error;
}
return new RSVP.Queue()
.push(function () {
return jIO.util.readBlobAsDataURL(blob);
})
.push(function (evt) {
attachment_dict[name] = evt.target.result;
});
};
MemoryStorage.prototype.removeAttachment = function (id, name) {
try {
delete this._database[id].attachments[name];
} catch (error) {
if (error instanceof TypeError) {
throw new jIO.util.jIOError(
"Cannot find document: " + id,
404
);
}
throw error;
}
};
MemoryStorage.prototype.hasCapacity = function (name) {
return ((name === "list") || (name === "include"));
};
MemoryStorage.prototype.buildQuery = function (options) {
var rows = [],
i;
for (i in this._database) {
if (this._database.hasOwnProperty(i)) {
if (options.include_docs === true) {
rows.push({
id: i,
value: {},
doc: JSON.parse(this._database[i].doc)
});
} else {
rows.push({
id: i,
value: {}
});
}
}
}
return rows;
};
jIO.addStorage('memory', MemoryStorage);
}(jIO, JSON, RSVP));
;/*
* Copyright 2013, Nexedi SA
* Released under the LGPL license.
......@@ -3508,7 +3686,7 @@ return new Parser;
/*jslint nomen: true, unparam: true */
/*global jIO, UriTemplate, FormData, RSVP, URI, Blob,
SimpleQuery, ComplexQuery*/
SimpleQuery, ComplexQuery, btoa*/
(function (jIO, UriTemplate, FormData, RSVP, URI, Blob,
SimpleQuery, ComplexQuery) {
......@@ -3521,8 +3699,9 @@ return new Parser;
"type": "GET",
"url": storage._url,
"xhrFields": {
withCredentials: true
}
withCredentials: storage._thisCredentials
},
"headers": storage._headers
});
})
.push(function (event) {
......@@ -3547,8 +3726,9 @@ return new Parser;
view: options._view
}),
"xhrFields": {
withCredentials: true
}
withCredentials: storage._thisCredentials
},
"headers": storage._headers
});
})
.push(undefined, function (error) {
......@@ -3625,8 +3805,8 @@ return new Parser;
});
}
function extractPropertyFromForm(context, id) {
return context.getAttachment(id, "view")
function extractPropertyFromForm(storage, id) {
return storage.getAttachment(id, "view")
.push(function (blob) {
return jIO.util.readBlobAsText(blob);
})
......@@ -3646,20 +3826,17 @@ return new Parser;
}
this._url = spec.url;
this._default_view_reference = spec.default_view_reference;
this._headers = null;
this._thisCredentials = true;
if (spec.login !== undefined && spec.password !== undefined) {
this._headers = {"Authorization": "Basic "
+ btoa(spec.login + ":" + spec.password)};
this._thisCredentials = false;
}
}
function convertJSONToGet(json) {
var key,
result = json.data;
// Remove all ERP5 hateoas links / convert them into jIO ID
for (key in result) {
if (result.hasOwnProperty(key)) {
if (!result[key]) {
delete result[key];
}
}
}
return result;
return json.data;
}
ERP5Storage.prototype.get = function (id) {
......@@ -3697,8 +3874,9 @@ return new Parser;
// "Content-Type": "application/json"
// },
"xhrFields": {
withCredentials: true
}
withCredentials: storage._thisCredentials
},
"headers": storage._headers
});
})
.push(function (response) {
......@@ -3720,7 +3898,7 @@ return new Parser;
};
ERP5Storage.prototype.post = function (data) {
var context = this,
var storage = this,
new_id;
return getSiteDocument(this)
......@@ -3733,15 +3911,16 @@ return new Parser;
url: site_hal._actions.add.href,
data: form_data,
xhrFields: {
withCredentials: true
}
withCredentials: storage._thisCredentials
},
"headers": storage._headers
});
})
.push(function (evt) {
var location = evt.target.getResponseHeader("X-Location"),
uri = new URI(location);
new_id = uri.segment(2);
return context.put(new_id, data);
return storage.put(new_id, data);
})
.push(function () {
return new_id;
......@@ -3749,9 +3928,9 @@ return new Parser;
};
ERP5Storage.prototype.put = function (id, data) {
var context = this;
var storage = this;
return extractPropertyFromForm(context, id)
return extractPropertyFromForm(storage, id)
.push(function (result) {
var key,
json = result.form_data,
......@@ -3784,7 +3963,7 @@ return new Parser;
403
);
}
return context.putAttachment(
return storage.putAttachment(
id,
result.action_href,
new Blob([JSON.stringify(form_data)], {type: "application/json"})
......@@ -3793,10 +3972,10 @@ return new Parser;
};
ERP5Storage.prototype.allAttachments = function (id) {
var context = this;
var storage = this;
return getDocumentAndHateoas(this, id)
.push(function () {
if (context._default_view_reference === undefined) {
if (storage._default_view_reference === undefined) {
return {
links: {}
};
......@@ -3809,6 +3988,7 @@ return new Parser;
};
ERP5Storage.prototype.getAttachment = function (id, action, options) {
var storage = this;
if (options === undefined) {
options = {};
}
......@@ -3855,8 +4035,9 @@ return new Parser;
"dataType": "blob",
"url": action,
"xhrFields": {
withCredentials: true
}
withCredentials: storage._thisCredentials
},
"headers": storage._headers
};
if (options.start !== undefined || options.end !== undefined) {
start = options.start || 0;
......@@ -3876,7 +4057,11 @@ return new Parser;
}
range = "bytes=" + start + "-" + end;
}
request_options.headers = {Range: range};
if (storage._headers === undefined) {
request_options.headers = {Range: range};
} else {
request_options.headers.Range = range;
}
}
return jIO.util.ajax(request_options);
})
......@@ -3895,6 +4080,7 @@ return new Parser;
};
ERP5Storage.prototype.putAttachment = function (id, name, blob) {
var storage = this;
// Assert we use a callable on a document from the ERP5 site
if (name.indexOf(this._url) !== 0) {
throw new jIO.util.jIOError("Can not store outside ERP5: " +
......@@ -3935,8 +4121,9 @@ return new Parser;
"url": name,
"data": data,
"xhrFields": {
withCredentials: true
}
withCredentials: storage._thisCredentials
},
"headers": storage._headers
});
});
};
......@@ -3985,6 +4172,7 @@ return new Parser;
// jIO.Query.objectToSearchText(options.query) :
// undefined);
// }
var storage = this;
return getSiteDocument(this)
.push(function (site_hal) {
var query = options.query,
......@@ -4053,8 +4241,9 @@ return new Parser;
local_roles: local_roles
}),
"xhrFields": {
withCredentials: true
}
withCredentials: storage._thisCredentials
},
"headers": storage._headers
});
})
.push(function (response) {
......@@ -4085,6 +4274,234 @@ return new Parser;
}(jIO, UriTemplate, FormData, RSVP, URI, Blob,
SimpleQuery, ComplexQuery));
;/*jslint nomen: true*/
/*global Blob, atob, btoa, RSVP*/
(function (jIO, Blob, atob, btoa, RSVP) {
"use strict";
/**
* The jIO DocumentStorage extension
*
* @class DocumentStorage
* @constructor
*/
function DocumentStorage(spec) {
this._sub_storage = jIO.createJIO(spec.sub_storage);
this._document_id = spec.document_id;
this._repair_attachment = spec.repair_attachment || false;
}
var DOCUMENT_EXTENSION = ".json",
DOCUMENT_REGEXP = new RegExp("^jio_document/([\\w=]+)" +
DOCUMENT_EXTENSION + "$"),
ATTACHMENT_REGEXP = new RegExp("^jio_attachment/([\\w=]+)/([\\w=]+)$");
function getSubAttachmentIdFromParam(id, name) {
if (name === undefined) {
return 'jio_document/' + btoa(id) + DOCUMENT_EXTENSION;
}
return 'jio_attachment/' + btoa(id) + "/" + btoa(name);
}
DocumentStorage.prototype.get = function (id) {
return this._sub_storage.getAttachment(
this._document_id,
getSubAttachmentIdFromParam(id),
{format: "json"}
);
};
DocumentStorage.prototype.allAttachments = function (id) {
return this._sub_storage.allAttachments(this._document_id)
.push(function (result) {
var attachments = {},
exec,
key;
for (key in result) {
if (result.hasOwnProperty(key)) {
if (ATTACHMENT_REGEXP.test(key)) {
exec = ATTACHMENT_REGEXP.exec(key);
try {
if (atob(exec[1]) === id) {
attachments[atob(exec[2])] = {};
}
} catch (error) {
// Check if unable to decode base64 data
if (!error instanceof ReferenceError) {
throw error;
}
}
}
}
}
return attachments;
});
};
DocumentStorage.prototype.put = function (doc_id, param) {
return this._sub_storage.putAttachment(
this._document_id,
getSubAttachmentIdFromParam(doc_id),
new Blob([JSON.stringify(param)], {type: "application/json"})
)
.push(function () {
return doc_id;
});
};
DocumentStorage.prototype.remove = function (id) {
var context = this;
return this.allAttachments(id)
.push(function (result) {
var key,
promise_list = [];
for (key in result) {
if (result.hasOwnProperty(key)) {
promise_list.push(context.removeAttachment(id, key));
}
}
return RSVP.all(promise_list);
})
.push(function () {
return context._sub_storage.removeAttachment(
context._document_id,
getSubAttachmentIdFromParam(id)
);
})
.push(function () {
return id;
});
};
DocumentStorage.prototype.repair = function () {
var context = this;
return this._sub_storage.repair.apply(this._sub_storage, arguments)
.push(function (result) {
if (context._repair_attachment) {
return context._sub_storage.allAttachments(context._document_id)
.push(function (result_dict) {
var promise_list = [],
id_dict = {},
attachment_dict = {},
id,
attachment,
exec,
key;
for (key in result_dict) {
if (result_dict.hasOwnProperty(key)) {
id = undefined;
attachment = undefined;
if (DOCUMENT_REGEXP.test(key)) {
try {
id = atob(DOCUMENT_REGEXP.exec(key)[1]);
} catch (error) {
// Check if unable to decode base64 data
if (!error instanceof ReferenceError) {
throw error;
}
}
if (id !== undefined) {
id_dict[id] = null;
}
} else if (ATTACHMENT_REGEXP.test(key)) {
exec = ATTACHMENT_REGEXP.exec(key);
try {
id = atob(exec[1]);
attachment = atob(exec[2]);
} catch (error) {
// Check if unable to decode base64 data
if (!error instanceof ReferenceError) {
throw error;
}
}
if (attachment !== undefined) {
if (!id_dict.hasOwnProperty(id)) {
if (!attachment_dict.hasOwnProperty(id)) {
attachment_dict[id] = {};
}
attachment_dict[id][attachment] = null;
}
}
}
}
}
for (id in attachment_dict) {
if (attachment_dict.hasOwnProperty(id)) {
if (!id_dict.hasOwnProperty(id)) {
for (attachment in attachment_dict[id]) {
if (attachment_dict[id].hasOwnProperty(attachment)) {
promise_list.push(context.removeAttachment(
id,
attachment
));
}
}
}
}
}
return RSVP.all(promise_list);
});
}
return result;
});
};
DocumentStorage.prototype.hasCapacity = function (capacity) {
return (capacity === "list");
};
DocumentStorage.prototype.buildQuery = function () {
return this._sub_storage.allAttachments(this._document_id)
.push(function (attachment_dict) {
var result = [],
key;
for (key in attachment_dict) {
if (attachment_dict.hasOwnProperty(key)) {
if (DOCUMENT_REGEXP.test(key)) {
try {
result.push({
id: atob(DOCUMENT_REGEXP.exec(key)[1]),
value: {}
});
} catch (error) {
// Check if unable to decode base64 data
if (!error instanceof ReferenceError) {
throw error;
}
}
}
}
}
return result;
});
};
DocumentStorage.prototype.getAttachment = function (id, name) {
return this._sub_storage.getAttachment(
this._document_id,
getSubAttachmentIdFromParam(id, name)
);
};
DocumentStorage.prototype.putAttachment = function (id, name, blob) {
return this._sub_storage.putAttachment(
this._document_id,
getSubAttachmentIdFromParam(id, name),
blob
);
};
DocumentStorage.prototype.removeAttachment = function (id, name) {
return this._sub_storage.removeAttachment(
this._document_id,
getSubAttachmentIdFromParam(id, name)
);
};
jIO.addStorage('document', DocumentStorage);
}(jIO, Blob, atob, btoa, RSVP));
;/*jslint nomen: true*/
/*global RSVP*/
(function (jIO, RSVP) {
"use strict";
......@@ -4414,141 +4831,6 @@ return new Parser;
Query) {
"use strict";
function getSubIdEqualSubProperty(storage, value, key) {
var query;
if (storage._no_sub_query_id) {
throw new jIO.util.jIOError('no sub query id active', 404);
}
query = new SimpleQuery({
key: key,
value: value,
type: "simple"
});
if (storage._query.query !== undefined) {
query = new ComplexQuery({
operator: "AND",
query_list: [query, storage._query.query],
type: "complex"
});
}
query = Query.objectToSearchText(query);
return storage._sub_storage.allDocs({
"query": query,
"sort_on": storage._query.sort_on,
"select_list": storage._query.select_list,
"limit": storage._query.limit
})
.push(function (data) {
if (data.data.rows.length === 0) {
throw new jIO.util.jIOError(
"Can not find id",
404
);
}
if (data.data.rows.length > 1) {
throw new TypeError("id must be unique field: " + key
+ ", result:" + data.data.rows.toString());
}
return data.data.rows[0].id;
});
}
/*jslint unparam: true*/
var mapping_function = {
"equalSubProperty": {
"mapToSubProperty": function (property, sub_doc, doc, args, id) {
sub_doc[args] = doc[property];
return args;
},
"mapToMainProperty": function (property, sub_doc, doc, args, sub_id) {
if (sub_doc.hasOwnProperty(args)) {
doc[property] = sub_doc[args];
}
return args;
},
"mapToSubId": function (storage, doc, id, args) {
if (doc !== undefined) {
if (storage._property_for_sub_id &&
doc.hasOwnProperty(storage._property_for_sub_id)) {
return doc[storage._property_for_sub_id];
}
if (doc.hasOwnProperty(args)) {
return doc[args];
}
}
return getSubIdEqualSubProperty(storage, id, storage._map_id[1]);
},
"mapToId": function (storage, sub_doc, sub_id, args) {
return sub_doc[args];
}
},
"equalValue": {
"mapToSubProperty": function (property, sub_doc, doc, args) {
sub_doc[property] = args;
return property;
},
"mapToMainProperty": function (property) {
return property;
}
},
"ignore": {
"mapToSubProperty": function () {
return false;
},
"mapToMainProperty": function (property) {
return property;
}
},
"equalSubId": {
"mapToSubProperty": function (property, sub_doc, doc) {
sub_doc[property] = doc[property];
return property;
},
"mapToMainProperty": function (property, sub_doc, doc, args, sub_id) {
if (sub_id === undefined && sub_doc.hasOwnProperty(property)) {
doc[property] = sub_doc[property];
} else {
doc[property] = sub_id;
}
return property;
},
"mapToSubId": function (storage, doc, id, args) {
return id;
},
"mapToId": function (storage, sub_doc, sub_id) {
return sub_id;
}
},
"keep": {
"mapToSubProperty": function (property, sub_doc, doc) {
sub_doc[property] = doc[property];
return property;
},
"mapToMainProperty": function (property, sub_doc, doc) {
doc[property] = sub_doc[property];
return property;
}
},
"switchPropertyValue": {
"mapToSubProperty": function (property, sub_doc, doc, args) {
sub_doc[args[0]] = args[1][doc[property]];
return args[0];
},
"mapToMainProperty": function (property, sub_doc, doc, args) {
var subvalue, value = sub_doc[args[0]];
for (subvalue in args[1]) {
if (args[1].hasOwnProperty(subvalue)) {
if (value === args[1][subvalue]) {
doc[property] = subvalue;
return property;
}
}
}
}
}
};
/*jslint unparam: false*/
function initializeQueryAndDefaultMapping(storage) {
var property, query_list = [];
for (property in storage._mapping_dict) {
......@@ -4591,15 +4873,14 @@ return new Parser;
}
function MappingStorage(spec) {
this._mapping_dict = spec.property || {};
this._mapping_dict = spec.mapping_dict || {};
this._sub_storage = jIO.createJIO(spec.sub_storage);
this._map_all_property = spec.map_all_property !== undefined ?
spec.map_all_property : true;
this._no_sub_query_id = spec.no_sub_query_id;
this._attachment_mapping_dict = spec.attachment || {};
this._attachment_mapping_dict = spec.attachment_mapping_dict || {};
this._query = spec.query || {};
this._map_id = spec.id || ["equalSubId"];
this._id_mapped = (spec.id !== undefined) ? spec.id[1] : false;
this._map_id = spec.map_id;
this._id_mapped = (spec.map_id !== undefined) ? spec.map_id[1] : false;
if (this._query.query !== undefined) {
this._query.query = QueryFactory.create(this._query.query);
......@@ -4623,42 +4904,113 @@ return new Parser;
}
function getSubStorageId(storage, id, doc) {
var query;
return new RSVP.Queue()
.push(function () {
var map_info = storage._map_id || ["equalSubId"];
if (storage._property_for_sub_id && doc !== undefined &&
doc.hasOwnProperty(storage._property_for_sub_id)) {
if (storage._property_for_sub_id !== undefined &&
doc !== undefined &&
doc[storage._property_for_sub_id] !== undefined) {
return doc[storage._property_for_sub_id];
}
return mapping_function[map_info[0]].mapToSubId(
storage,
doc,
id,
map_info[1]
if (!storage._id_mapped) {
return id;
}
if (storage._map_id[0] === "equalSubProperty") {
query = new SimpleQuery({
key: storage._map_id[1],
value: id,
type: "simple"
});
if (storage._query.query !== undefined) {
query = new ComplexQuery({
operator: "AND",
query_list: [query, storage._query.query],
type: "complex"
});
}
query = Query.objectToSearchText(query);
return storage._sub_storage.allDocs({
"query": query,
"sort_on": storage._query.sort_on,
"select_list": storage._query.select_list,
"limit": storage._query.limit
})
.push(function (data) {
if (data.data.rows.length === 0) {
throw new jIO.util.jIOError(
"Can not find id",
404
);
}
if (data.data.rows.length > 1) {
throw new TypeError("id must be unique field: " + id
+ ", result:" + data.data.rows.toString());
}
return data.data.rows[0].id;
});
}
throw new jIO.util.jIOError(
"Unsuported option: " + storage._mapping_dict.id,
400
);
});
}
function mapToSubProperty(storage, property, sub_doc, doc, id) {
var mapping_info = storage._mapping_dict[property] || ["keep"];
return mapping_function[mapping_info[0]].mapToSubProperty(
property,
sub_doc,
doc,
mapping_info[1],
id
function mapToSubProperty(storage, property, sub_doc, doc) {
var mapping_function, parameter;
if (storage._mapping_dict[property] !== undefined) {
mapping_function = storage._mapping_dict[property][0];
parameter = storage._mapping_dict[property][1];
if (mapping_function === "equalSubProperty") {
sub_doc[parameter] = doc[property];
return parameter;
}
if (mapping_function === "equalValue") {
sub_doc[property] = parameter;
return property;
}
if (mapping_function === "ignore" || mapping_function === "equalSubId") {
return false;
}
}
if (!storage._map_all_property) {
return false;
}
if (storage._map_all_property) {
sub_doc[property] = doc[property];
return property;
}
throw new jIO.util.jIOError(
"Unsuported option(s): " + storage._mapping_dict[property],
400
);
}
function mapToMainProperty(storage, property, sub_doc, doc, sub_id) {
var mapping_info = storage._mapping_dict[property] || ["keep"];
return mapping_function[mapping_info[0]].mapToMainProperty(
property,
sub_doc,
doc,
mapping_info[1],
sub_id
);
function mapToMainProperty(storage, property, sub_doc, doc) {
var mapping_function, parameter;
if (storage._mapping_dict[property] !== undefined) {
mapping_function = storage._mapping_dict[property][0];
parameter = storage._mapping_dict[property][1];
if (mapping_function === "equalSubProperty") {
if (sub_doc.hasOwnProperty(parameter)) {
doc[property] = sub_doc[parameter];
}
return parameter;
}
if (mapping_function === "equalValue") {
return property;
}
if (mapping_function === "ignore") {
return property;
}
}
if (storage._map_all_property) {
if (sub_doc.hasOwnProperty(property)) {
doc[property] = sub_doc[property];
}
return property;
}
return false;
}
function mapToMainDocument(storage, sub_doc, sub_id) {
......@@ -4667,13 +5019,7 @@ return new Parser;
property_list = [storage._id_mapped];
for (property in storage._mapping_dict) {
if (storage._mapping_dict.hasOwnProperty(property)) {
property_list.push(mapToMainProperty(
storage,
property,
sub_doc,
doc,
sub_id
));
property_list.push(mapToMainProperty(storage, property, sub_doc, doc));
}
}
if (storage._map_all_property) {
......@@ -4685,8 +5031,9 @@ return new Parser;
}
}
}
if (storage._map_for_sub_storage_id !== undefined) {
doc[storage._map_for_sub_storage_id] = sub_id;
if (storage._property_for_sub_id !== undefined &&
sub_id !== undefined) {
doc[storage._property_for_sub_id] = sub_id;
}
return doc;
}
......@@ -4696,7 +5043,7 @@ return new Parser;
for (property in doc) {
if (doc.hasOwnProperty(property)) {
mapToSubProperty(storage, property, sub_doc, doc, id);
mapToSubProperty(storage, property, sub_doc, doc);
}
}
for (property in storage._default_mapping) {
......@@ -4704,36 +5051,36 @@ return new Parser;
sub_doc[property] = storage._default_mapping[property];
}
}
if (storage._map_id[0] === "equalSubProperty" && id !== undefined) {
sub_doc[storage._map_id[1]] = id;
if (storage._id_mapped && id !== undefined) {
sub_doc[storage._id_mapped] = id;
}
return sub_doc;
}
function handleAttachment(storage, argument_list, method) {
return getSubStorageId(storage, argument_list[0])
function handleAttachment(context, argument_list, method) {
return getSubStorageId(context, argument_list[0])
.push(function (sub_id) {
argument_list[0] = sub_id;
argument_list[1] = getAttachmentId(
storage,
context,
sub_id,
argument_list[1],
method
);
return storage._sub_storage[method + "Attachment"].apply(
storage._sub_storage,
return context._sub_storage[method + "Attachment"].apply(
context._sub_storage,
argument_list
);
});
}
MappingStorage.prototype.get = function (id) {
var storage = this;
var context = this;
return getSubStorageId(this, id)
.push(function (sub_id) {
return storage._sub_storage.get(sub_id)
return context._sub_storage.get(sub_id)
.push(function (sub_doc) {
return mapToMainDocument(storage, sub_doc, sub_id);
return mapToMainDocument(context, sub_doc, sub_id);
});
});
};
......@@ -4757,15 +5104,15 @@ return new Parser;
};
MappingStorage.prototype.put = function (id, doc) {
var storage = this,
var context = this,
sub_doc = mapToSubstorageDocument(this, doc, id);
return getSubStorageId(this, id, doc)
.push(function (sub_id) {
return storage._sub_storage.put(sub_id, sub_doc);
return context._sub_storage.put(sub_id, sub_doc);
})
.push(undefined, function (error) {
if (error instanceof jIO.util.jIOError && error.status_code === 404) {
return storage._sub_storage.post(sub_doc);
return context._sub_storage.post(sub_doc);
}
throw error;
})
......@@ -4775,10 +5122,10 @@ return new Parser;
};
MappingStorage.prototype.remove = function (id) {
var storage = this;
var context = this;
return getSubStorageId(this, id)
.push(function (sub_id) {
return storage._sub_storage.remove(sub_id);
return context._sub_storage.remove(sub_id);
})
.push(function () {
return id;
......@@ -4804,19 +5151,19 @@ return new Parser;
};
MappingStorage.prototype.allAttachments = function (id) {
var storage = this, sub_id;
return getSubStorageId(storage, id)
var context = this, sub_id;
return getSubStorageId(context, id)
.push(function (sub_id_result) {
sub_id = sub_id_result;
return storage._sub_storage.allAttachments(sub_id);
return context._sub_storage.allAttachments(sub_id);
})
.push(function (result) {
var attachment_id,
attachments = {},
mapping_dict = {};
for (attachment_id in storage._attachment_mapping_dict) {
if (storage._attachment_mapping_dict.hasOwnProperty(attachment_id)) {
mapping_dict[getAttachmentId(storage, sub_id, attachment_id, "get")]
for (attachment_id in context._attachment_mapping_dict) {
if (context._attachment_mapping_dict.hasOwnProperty(attachment_id)) {
mapping_dict[getAttachmentId(context, sub_id, attachment_id, "get")]
= attachment_id;
}
}
......@@ -4842,10 +5189,10 @@ return new Parser;
};
MappingStorage.prototype.bulk = function (id_list) {
var storage = this;
var context = this;
function mapId(parameter) {
return getSubStorageId(storage, parameter.parameter_list[0])
return getSubStorageId(context, parameter.parameter_list[0])
.push(function (id) {
return {"method": parameter.method, "parameter_list": [id]};
});
......@@ -4857,13 +5204,13 @@ return new Parser;
return RSVP.all(promise_list);
})
.push(function (id_list_mapped) {
return storage._sub_storage.bulk(id_list_mapped);
return context._sub_storage.bulk(id_list_mapped);
})
.push(function (result) {
var mapped_result = [], i;
for (i = 0; i < result.length; i += 1) {
mapped_result.push(mapToMainDocument(
storage,
context,
result[i]
));
}
......@@ -4872,7 +5219,7 @@ return new Parser;
};
MappingStorage.prototype.buildQuery = function (option) {
var storage = this,
var context = this,
i,
query,
property,
......@@ -4891,7 +5238,7 @@ return new Parser;
one_query.query_list = query_list;
return one_query;
}
key = mapToMainProperty(storage, one_query.key, {}, {});
key = mapToMainProperty(context, one_query.key, {}, {});
if (key) {
one_query.key = key;
return one_query;
......@@ -4962,25 +5309,21 @@ return new Parser;
}
)
.push(function (result) {
var sub_doc, map_info = storage._map_id || ["equalSubId"];
var doc;
for (i = 0; i < result.data.total_rows; i += 1) {
sub_doc = result.data.rows[i].value;
result.data.rows[i].id =
mapping_function[map_info[0]].mapToId(
storage,
sub_doc,
result.data.rows[i].id,
map_info[1]
);
doc = result.data.rows[i].value;
result.data.rows[i].value =
mapToMainDocument(
storage,
sub_doc
context,
doc
);
if (context._id_mapped) {
result.data.rows[i].id = doc[context._id_mapped];
}
}
return result.data.rows;
});
};
jIO.addStorage('mapping', MappingStorage);
}(jIO, RSVP, UriTemplate, SimpleQuery, ComplexQuery, QueryFactory, Query));
\ No newline at end of file
}(jIO, RSVP, UriTemplate, SimpleQuery, ComplexQuery, QueryFactory, Query));
/*! jio v3.13.0 2017-03-15 */
function parseStringToObject(a){var b=function(){var a,b,c=[],d=arguments;for(a=0;a<d.length;a+=1)for(b=0;b<d[a].length;b+=1)c.push(d[a][b]);return c},c=function(a,b,c){var d={type:"simple",key:a,value:b};return void 0!==c&&(d.operator=c),d},d=function(a){return"NOT"===a.operator?a.query_list[0]:{type:"complex",operator:"NOT",query_list:[a]}},e=function(a,c){var d,e=[];for(d=0;d<c.length;d+=1)c[d].operator===a?e=b(e,c[d].query_list):e.push(c[d]);return{type:"complex",operator:a,query_list:e}},f=function(a,b){var c;if("complex"===a.type){for(c=0;c<a.query_list.length;++c)f(a.query_list[c],b);return!0}return"simple"!==a.type||a.key?!1:(a.key=b,!0)},g=function(){function a(){this.yy={}}var b=function(a,b,c,d){for(c=c||{},d=a.length;d--;c[a[d]]=b);return c},g=[1,5],h=[1,7],i=[1,8],j=[1,10],k=[1,12],l=[1,6,7,15],m=[1,6,7,9,12,14,15,16,19,21],n=[1,6,7,9,11,12,14,15,16,19,21],o=[2,17],p={trace:function(){},yy:{},symbols_:{error:2,begin:3,search_text:4,end:5,EOF:6,NEWLINE:7,and_expression:8,OR:9,boolean_expression:10,AND:11,NOT:12,expression:13,LEFT_PARENTHESE:14,RIGHT_PARENTHESE:15,WORD:16,DEFINITION:17,value:18,OPERATOR:19,string:20,QUOTE:21,QUOTED_STRING:22,$accept:0,$end:1},terminals_:{2:"error",6:"EOF",7:"NEWLINE",9:"OR",11:"AND",12:"NOT",14:"LEFT_PARENTHESE",15:"RIGHT_PARENTHESE",16:"WORD",17:"DEFINITION",19:"OPERATOR",21:"QUOTE",22:"QUOTED_STRING"},productions_:[0,[3,2],[5,0],[5,1],[5,1],[4,1],[4,2],[4,3],[8,1],[8,3],[10,2],[10,1],[13,3],[13,3],[13,1],[18,2],[18,1],[20,1],[20,3]],performAction:function(a,b,g,h,i,j,k){var l=j.length-1;switch(i){case 1:return j[l-1];case 5:case 8:case 11:case 14:case 16:this.$=j[l];break;case 6:this.$=e("OR",[j[l-1],j[l]]);break;case 7:this.$=e("OR",[j[l-2],j[l]]);break;case 9:this.$=e("AND",[j[l-2],j[l]]);break;case 10:this.$=d(j[l]);break;case 12:this.$=j[l-1];break;case 13:f(j[l],j[l-2]),this.$=j[l];break;case 15:j[l].operator=j[l-1],this.$=j[l];break;case 17:this.$=c("",j[l]);break;case 18:this.$=c("",j[l-1])}},table:[{3:1,4:2,8:3,10:4,12:g,13:6,14:h,16:i,18:9,19:j,20:11,21:k},{1:[3]},{1:[2,2],5:13,6:[1,14],7:[1,15]},b(l,[2,5],{8:3,10:4,13:6,18:9,20:11,4:16,9:[1,17],12:g,14:h,16:i,19:j,21:k}),b(m,[2,8],{11:[1,18]}),{13:19,14:h,16:i,18:9,19:j,20:11,21:k},b(n,[2,11]),{4:20,8:3,10:4,12:g,13:6,14:h,16:i,18:9,19:j,20:11,21:k},b(n,o,{17:[1,21]}),b(n,[2,14]),{16:[1,23],20:22,21:k},b(n,[2,16]),{22:[1,24]},{1:[2,1]},{1:[2,3]},{1:[2,4]},b(l,[2,6]),{4:25,8:3,10:4,12:g,13:6,14:h,16:i,18:9,19:j,20:11,21:k},{8:26,10:4,12:g,13:6,14:h,16:i,18:9,19:j,20:11,21:k},b(n,[2,10]),{15:[1,27]},{13:28,14:h,16:i,18:9,19:j,20:11,21:k},b(n,[2,15]),b(n,o),{21:[1,29]},b(l,[2,7]),b(m,[2,9]),b(n,[2,12]),b(n,[2,13]),b(n,[2,18])],defaultActions:{13:[2,1],14:[2,3],15:[2,4]},parseError:function(a,b){function c(a,b){this.message=a,this.hash=b}if(!b.recoverable)throw c.prototype=new Error,new c(a,b);this.trace(a)},parse:function(a){var b=this,c=[0],d=[null],e=[],f=this.table,g="",h=0,i=0,j=0,k=2,l=1,m=e.slice.call(arguments,1),n=Object.create(this.lexer),o={yy:{}};for(var p in this.yy)Object.prototype.hasOwnProperty.call(this.yy,p)&&(o.yy[p]=this.yy[p]);n.setInput(a,o.yy),o.yy.lexer=n,o.yy.parser=this,"undefined"==typeof n.yylloc&&(n.yylloc={});var q=n.yylloc;e.push(q);var r=n.options&&n.options.ranges;"function"==typeof o.yy.parseError?this.parseError=o.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;for(var s,t,u,v,w,x,y,z,A,B=function(){var a;return a=n.lex()||l,"number"!=typeof a&&(a=b.symbols_[a]||a),a},C={};;){if(u=c[c.length-1],this.defaultActions[u]?v=this.defaultActions[u]:((null===s||"undefined"==typeof s)&&(s=B()),v=f[u]&&f[u][s]),"undefined"==typeof v||!v.length||!v[0]){var D="";A=[];for(x in f[u])this.terminals_[x]&&x>k&&A.push("'"+this.terminals_[x]+"'");D=n.showPosition?"Parse error on line "+(h+1)+":\n"+n.showPosition()+"\nExpecting "+A.join(", ")+", got '"+(this.terminals_[s]||s)+"'":"Parse error on line "+(h+1)+": Unexpected "+(s==l?"end of input":"'"+(this.terminals_[s]||s)+"'"),this.parseError(D,{text:n.match,token:this.terminals_[s]||s,line:n.yylineno,loc:q,expected:A})}if(v[0]instanceof Array&&v.length>1)throw new Error("Parse Error: multiple actions possible at state: "+u+", token: "+s);switch(v[0]){case 1:c.push(s),d.push(n.yytext),e.push(n.yylloc),c.push(v[1]),s=null,t?(s=t,t=null):(i=n.yyleng,g=n.yytext,h=n.yylineno,q=n.yylloc,j>0&&j--);break;case 2:if(y=this.productions_[v[1]][1],C.$=d[d.length-y],C._$={first_line:e[e.length-(y||1)].first_line,last_line:e[e.length-1].last_line,first_column:e[e.length-(y||1)].first_column,last_column:e[e.length-1].last_column},r&&(C._$.range=[e[e.length-(y||1)].range[0],e[e.length-1].range[1]]),w=this.performAction.apply(C,[g,i,h,o.yy,v[1],d,e].concat(m)),"undefined"!=typeof w)return w;y&&(c=c.slice(0,-1*y*2),d=d.slice(0,-1*y),e=e.slice(0,-1*y)),c.push(this.productions_[v[1]][0]),d.push(C.$),e.push(C._$),z=f[c[c.length-2]][c[c.length-1]],c.push(z);break;case 3:return!0}}return!0}},q=function(){var a={EOF:1,parseError:function(a,b){if(!this.yy.parser)throw new Error(a);this.yy.parser.parseError(a,b)},setInput:function(a,b){return this.yy=b||this.yy||{},this._input=a,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var a=this._input[0];this.yytext+=a,this.yyleng++,this.offset++,this.match+=a,this.matched+=a;var b=a.match(/(?:\r\n?|\n).*/g);return b?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),a},unput:function(a){var b=a.length,c=a.split(/(?:\r\n?|\n)/g);this._input=a+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-b),this.offset-=b;var d=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),c.length-1&&(this.yylineno-=c.length-1);var e=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:c?(c.length===d.length?this.yylloc.first_column:0)+d[d.length-c.length].length-c[0].length:this.yylloc.first_column-b},this.options.ranges&&(this.yylloc.range=[e[0],e[0]+this.yyleng-b]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){return this.options.backtrack_lexer?(this._backtrack=!0,this):this.parseError("Lexical error on line "+(this.yylineno+1)+". You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},less:function(a){this.unput(this.match.slice(a))},pastInput:function(){var a=this.matched.substr(0,this.matched.length-this.match.length);return(a.length>20?"...":"")+a.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var a=this.match;return a.length<20&&(a+=this._input.substr(0,20-a.length)),(a.substr(0,20)+(a.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var a=this.pastInput(),b=new Array(a.length+1).join("-");return a+this.upcomingInput()+"\n"+b+"^"},test_match:function(a,b){var c,d,e;if(this.options.backtrack_lexer&&(e={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(e.yylloc.range=this.yylloc.range.slice(0))),d=a[0].match(/(?:\r\n?|\n).*/g),d&&(this.yylineno+=d.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:d?d[d.length-1].length-d[d.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+a[0].length},this.yytext+=a[0],this.match+=a[0],this.matches=a,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(a[0].length),this.matched+=a[0],c=this.performAction.call(this,this.yy,this,b,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),c)return c;if(this._backtrack){for(var f in e)this[f]=e[f];return!1}return!1},next:function(){if(this.done)return this.EOF;this._input||(this.done=!0);var a,b,c,d;this._more||(this.yytext="",this.match="");for(var e=this._currentRules(),f=0;f<e.length;f++)if(c=this._input.match(this.rules[e[f]]),c&&(!b||c[0].length>b[0].length)){if(b=c,d=f,this.options.backtrack_lexer){if(a=this.test_match(c,e[f]),a!==!1)return a;if(this._backtrack){b=!1;continue}return!1}if(!this.options.flex)break}return b?(a=this.test_match(b,e[d]),a!==!1?a:!1):""===this._input?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+". Unrecognized text.\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){var a=this.next();return a?a:this.lex()},begin:function(a){this.conditionStack.push(a)},popState:function(){var a=this.conditionStack.length-1;return a>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(a){return a=this.conditionStack.length-1-Math.abs(a||0),a>=0?this.conditionStack[a]:"INITIAL"},pushState:function(a){this.begin(a)},stateStackSize:function(){return this.conditionStack.length},options:{},performAction:function(a,b,c,d){switch(c){case 0:return this.begin("letsquote"),"QUOTE";case 1:return this.popState(),this.begin("endquote"),"QUOTED_STRING";case 2:return this.popState(),"QUOTE";case 3:break;case 4:return"LEFT_PARENTHESE";case 5:return"RIGHT_PARENTHESE";case 6:return"AND";case 7:return"OR";case 8:return"NOT";case 9:return"DEFINITION";case 10:return 19;case 11:return 16;case 12:return 6}},rules:[/^(?:")/,/^(?:(\\"|[^"])*)/,/^(?:")/,/^(?:[^\S]+)/,/^(?:\()/,/^(?:\))/,/^(?:AND\b)/,/^(?:OR\b)/,/^(?:NOT\b)/,/^(?::)/,/^(?:(!?=|<=?|>=?))/,/^(?:[^\s\n"():><!=]+)/,/^(?:$)/],conditions:{endquote:{rules:[2],inclusive:!1},letsquote:{rules:[1],inclusive:!1},INITIAL:{rules:[0,3,4,5,6,7,8,9,10,11,12],inclusive:!0}}};return a}();return p.lexer=q,a.prototype=p,p.Parser=a,new a}();return g.parse(a)}!function(a,b,c){"use strict";function d(a){var b,c=[];if(void 0===a)return void 0;for(Array.isArray(a)||(a=[a]),b=0;b<a.length;b+=1)"object"==typeof a[b]?c[b]=a[b].content:c[b]=a[b];return c}function e(a,b){var c;if("descending"===b)c=1;else{if("ascending"!==b)throw new TypeError("Query.sortFunction(): Argument 2 must be 'ascending' or 'descending'");c=-1}return function(b,e){var f,g;for(b=d(b[a])||[],e=d(e[a])||[],g=b.length>e.length?b.length:e.length,f=0;g>f;f+=1){if(void 0===b[f])return c;if(void 0===e[f])return-c;if(b[f]>e[f])return-c;if(b[f]<e[f])return c}return 0}}function f(a,b){var c;if(!Array.isArray(a))throw new TypeError("jioquery.sortOn(): Argument 1 is not of type 'array'");for(c=a.length-1;c>=0;c-=1)b.sort(e(a[c][0],a[c][1]));return b}function g(a,b){if(!Array.isArray(a))throw new TypeError("jioquery.limit(): Argument 1 is not of type 'array'");if(!Array.isArray(b))throw new TypeError("jioquery.limit(): Argument 2 is not of type 'array'");return b.splice(0,a[0]),a[1]&&b.splice(a[1]),b}function h(a,b){var c,d,e;if(!Array.isArray(a))throw new TypeError("jioquery.select(): Argument 1 is not of type Array");if(!Array.isArray(b))throw new TypeError("jioquery.select(): Argument 2 is not of type Array");for(c=0;c<b.length;c+=1){for(e={},d=0;d<a.length;d+=1)b[c].hasOwnProperty([a[d]])&&(e[a[d]]=b[c][a[d]]);for(d in e)if(e.hasOwnProperty(d)){b[c]=e;break}}return b}function i(){}function j(){}function k(a){return a.replace(t,"\\$&")}function l(a,b){a.super_=b,a.prototype=Object.create(b.prototype,{constructor:{configurable:!0,enumerable:!1,writable:!0,value:a}})}function m(a,b){if("string"!=typeof a)throw new TypeError("jioquery.searchTextToRegExp(): Argument 1 is not of type 'string'");return b===!1?new RegExp("^"+k(a)+"$"):new RegExp("^"+k(a).replace(u,".*").replace(v,".")+"$")}function n(a,b){i.call(this),this.operator=a.operator,this.query_list=a.query_list||[],this.query_list=this.query_list.map(function(a){return j.create(a,b)})}function o(a){var b=[];if("complex"===a.type)return b.push("("),(a.query_list||[]).forEach(function(c){b.push(o(c)),b.push(a.operator)}),b.length-=1,b.push(")"),b.join(" ");if("simple"===a.type)return(a.key?a.key+": ":"")+(a.operator||"")+' "'+a.value+'"';throw new TypeError("This object is not a query")}function p(a){var b;if(void 0!==a){if("object"!=typeof a)throw new TypeError("SimpleQuery().create(): key_schema is not of type 'object'");if(void 0===a.key_set)throw new TypeError("SimpleQuery().create(): key_schema has no 'key_set' property");for(b in a)if(a.hasOwnProperty(b))switch(b){case"key_set":case"cast_lookup":case"match_lookup":break;default:throw new TypeError("SimpleQuery().create(): key_schema has unknown property '"+b+"'")}}}function q(a,b){i.call(this),p(b),this._key_schema=b||{},this.operator=a.operator,this.key=a.key,this.value=a.value}function r(a){var b;if(void 0===a.read_from)throw new TypeError("Custom key is missing the read_from property");for(b in a)if(a.hasOwnProperty(b))switch(b){case"read_from":case"cast_to":case"equal_match":break;default:throw new TypeError("Custom key has unknown property '"+b+"'")}}var s={},t=/[\-\[\]{}()*+?.,\\\^$|#\s]/g,u=/%/g,v=/_/g,w=/^(?:AND|OR|NOT)$/i,x=/^(?:!?=|<=?|>=?)$/i;i.prototype.exec=function(b,c){if(!Array.isArray(b))throw new TypeError("Query().exec(): Argument 1 is not of type 'array'");if(void 0===c&&(c={}),"object"!=typeof c)throw new TypeError("Query().exec(): Optional argument 2 is not of type 'object'");var d,e=this;for(d=b.length-1;d>=0;d-=1)e.match(b[d])||b.splice(d,1);return c.sort_on&&f(c.sort_on,b),c.limit&&g(c.limit,b),h(c.select_list||[],b),(new a.Queue).push(function(){return b})},i.prototype.match=function(){return!0},i.prototype.parse=function(b){function c(b,d){function f(a){i.push(function(){return b.parsed=h.query_list[a],c(b,d)}).push(function(){h.query_list[a]=b.parsed})}var g,h=b.parsed,i=new a.Queue;if("complex"===h.type){for(g=0;g<h.query_list.length;g+=1)f(g);return i.push(function(){return b.parsed=h,e.onParseComplexQuery(b,d)})}return"simple"===h.type?e.onParseSimpleQuery(b,d):void 0}var d,e=this;return d={parsed:JSON.parse(JSON.stringify(e.serialized()))},(new a.Queue).push(function(){return e.onParseStart(d,b)}).push(function(){return c(d,b)}).push(function(){return e.onParseEnd(d,b)}).push(function(){return d.parsed})},i.prototype.toString=function(){return""},i.prototype.serialized=function(){return void 0},l(n,i),n.prototype.operator="AND",n.prototype.type="complex",n.prototype.match=function(a){var b=this.operator;return w.test(b)||(b="AND"),this[b.toUpperCase()](a)},n.prototype.toString=function(){var a=[],b=this.operator;return"NOT"===this.operator?(a.push("NOT ("),a.push(this.query_list[0].toString()),a.push(")"),a.join(" ")):(this.query_list.forEach(function(c){a.push("("),a.push(c.toString()),a.push(")"),a.push(b)}),a.length-=1,a.join(" "))},n.prototype.serialized=function(){var a={type:"complex",operator:this.operator,query_list:[]};return this.query_list.forEach(function(b){a.query_list.push("function"==typeof b.toJSON?b.toJSON():b)}),a},n.prototype.toJSON=n.prototype.serialized,n.prototype.AND=function(a){for(var b=!0,c=0;b&&c!==this.query_list.length;)b=this.query_list[c].match(a),c+=1;return b},n.prototype.OR=function(a){for(var b=!1,c=0;!b&&c!==this.query_list.length;)b=this.query_list[c].match(a),c+=1;return b},n.prototype.NOT=function(a){return!this.query_list[0].match(a)},j.create=function(a,b){if(""===a)return new i;if("string"==typeof a&&(a=c(a)),"string"==typeof(a||{}).type&&s[a.type])return new s[a.type](a,b);throw new TypeError("QueryFactory.create(): Argument 1 is not a search text or a parsable object")},l(q,i),q.prototype.type="simple",q.prototype.match=function(a){var b=null,c=null,d=null,e=null,f=this.operator,g=null,h=this.key;if(x.test(f)||(f=u.test(this.value)?"like":"="),e=this[f],this._key_schema.key_set&&void 0!==this._key_schema.key_set[h]&&(h=this._key_schema.key_set[h]),"object"==typeof h){if(r(h),b=a[h.read_from],c=h.equal_match,"string"==typeof c&&(c=this._key_schema.match_lookup[c]),void 0!==c&&(e="="===f||"like"===f?c:e),g=this.value,d=h.cast_to){"string"==typeof d&&(d=this._key_schema.cast_lookup[d]);try{g=d(g)}catch(i){g=void 0}try{b=d(b)}catch(i){b=void 0}}}else b=a[h],g=this.value;return void 0===b||void 0===g?!1:e(b,g)},q.prototype.toString=function(){return(this.key?this.key+":":"")+(this.operator?" "+this.operator:"")+' "'+this.value+'"'},q.prototype.serialized=function(){var a={type:"simple",key:this.key,value:this.value};return void 0!==this.operator&&(a.operator=this.operator),a},q.prototype.toJSON=q.prototype.serialized,q.prototype["="]=function(a,b){var c,d;for(Array.isArray(a)||(a=[a]),d=0;d<a.length;d+=1){if(c=a[d],"object"==typeof c&&c.hasOwnProperty("content")&&(c=c.content),"function"==typeof c.cmp)return 0===c.cmp(b);if(b.toString()===c.toString())return!0}return!1},q.prototype.like=function(a,b){var c,d;for(Array.isArray(a)||(a=[a]),d=0;d<a.length;d+=1){if(c=a[d],"object"==typeof c&&c.hasOwnProperty("content")&&(c=c.content),"function"==typeof c.cmp)return 0===c.cmp(b);if(m(b.toString()).test(c.toString()))return!0}return!1},q.prototype["!="]=function(a,b){var c,d;for(Array.isArray(a)||(a=[a]),d=0;d<a.length;d+=1){if(c=a[d],"object"==typeof c&&c.hasOwnProperty("content")&&(c=c.content),"function"==typeof c.cmp)return 0!==c.cmp(b);if(b.toString()===c.toString())return!1}return!0},q.prototype["<"]=function(a,b){var c;return Array.isArray(a)||(a=[a]),c=a[0],"object"==typeof c&&c.hasOwnProperty("content")&&(c=c.content),"function"==typeof c.cmp?c.cmp(b)<0:b>c},q.prototype["<="]=function(a,b){var c;return Array.isArray(a)||(a=[a]),c=a[0],"object"==typeof c&&c.hasOwnProperty("content")&&(c=c.content),"function"==typeof c.cmp?c.cmp(b)<=0:b>=c},q.prototype[">"]=function(a,b){var c;return Array.isArray(a)||(a=[a]),c=a[0],"object"==typeof c&&c.hasOwnProperty("content")&&(c=c.content),"function"==typeof c.cmp?c.cmp(b)>0:c>b},q.prototype[">="]=function(a,b){var c;return Array.isArray(a)||(a=[a]),c=a[0],"object"==typeof c&&c.hasOwnProperty("content")&&(c=c.content),"function"==typeof c.cmp?c.cmp(b)>=0:c>=b},s.simple=q,s.complex=n,i.parseStringToObject=c,i.objectToSearchText=o,b.Query=i,b.SimpleQuery=q,b.ComplexQuery=n,b.QueryFactory=j}(RSVP,window,parseStringToObject),function(a,b){"use strict";var c,d="year",e="month",f="day",g="hour",h="minute",i="second",j="millisecond",k={year:0,month:1,day:2,hour:3,minute:4,second:5,millisecond:6},l=function(a,b){return k[a]<k[b]?a:b};c=function(a){if(!(this instanceof c))return new c(a);if(a instanceof c)return this.mom=a.mom.clone(),void(this._precision=a._precision);if(void 0===a)return this.mom=b(),void this.setPrecision(j);if(this.mom=null,this._str=a,a.match(/\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+\-][0-2]\d:[0-5]\d|Z)/)||a.match(/\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d\.\d\d\d/)?(this.mom=b(a),this.setPrecision(j)):a.match(/\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+\-][0-2]\d:[0-5]\d|Z)/)||a.match(/\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d/)?(this.mom=b(a),this.setPrecision(i)):a.match(/\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+\-][0-2]\d:[0-5]\d|Z)/)||a.match(/\d\d\d\d-\d\d-\d\d \d\d:\d\d/)?(this.mom=b(a),this.setPrecision(h)):a.match(/\d\d\d\d-\d\d-\d\d \d\d/)?(this.mom=b(a),this.setPrecision(g)):a.match(/\d\d\d\d-\d\d-\d\d/)?(this.mom=b(a),this.setPrecision(f)):a.match(/\d\d\d\d-\d\d/)?(this.mom=b(a),this.setPrecision(e)):a.match(/\d\d\d\d/)&&(this.mom=b(a,"YYYY"),this.setPrecision(d)),!this.mom)throw new Error("Cannot parse: "+a)},c.prototype.setPrecision=function(a){this._precision=a},c.prototype.getPrecision=function(){return this._precision},c.prototype.cmp=function(a){var b=this.mom,c=a.mom,d=l(this._precision,a._precision);return b.isBefore(c,d)?-1:b.isSame(c,d)?0:1},c.prototype.toPrecisionString=function(a){var b;if(a=a||this._precision,b={millisecond:"YYYY-MM-DD HH:mm:ss.SSS",second:"YYYY-MM-DD HH:mm:ss",minute:"YYYY-MM-DD HH:mm",hour:"YYYY-MM-DD HH",day:"YYYY-MM-DD",month:"YYYY-MM",year:"YYYY"}[a],!b)throw new TypeError("Unsupported precision value '"+a+"'");return this.mom.format(b)},c.prototype.toString=function(){return this._str},a.jiodate={JIODate:c,YEAR:d,MONTH:e,DAY:f,HOUR:g,MIN:h,SEC:i,MSEC:j}}(window,moment),function(a,b,c,d,e,f,g,h,i,j){"use strict";function k(a,b){if(void 0!==a&&"string"!=typeof a)throw new TypeError("You must pass a string.");this.message=a||"Default Message",this.status_code=b||500}function l(a){var c=new XMLHttpRequest;return new b.Promise(function(b,d,e){var f,g=new StreamBuffers.WritableStreamBuffer;if(c.open(a.type||"GET",a.url,!0),c.responseType=a.dataType||"","object"==typeof a.headers&&null!==a.headers)for(f in a.headers)a.headers.hasOwnProperty(f)&&c.setRequestHeader(f,a.headers[f]);if(c.setRequestHeader("Accept","*/*"),c.addEventListener("load",function(a){return a.target.status>=400?d(a):void b(a)}),c.addEventListener("error",d),c.addEventListener("progress",e),"object"==typeof a.xhrFields&&null!==a.xhrFields)for(f in a.xhrFields)a.xhrFields.hasOwnProperty(f)&&(c[f]=a.xhrFields[f]);"function"==typeof a.beforeSend&&a.beforeSend(c),a.data instanceof FormData?(c.setRequestHeader("Content-Type","multipart/form-data; boundary="+a.data.getBoundary()),a.data.pipe(g),c.send(g.getContents())):c.send(a.data)},function(){c.abort()})}function m(a,c){var d=new g;return new b.Promise(function(b,e,f){d.addEventListener("load",b),d.addEventListener("error",e),d.addEventListener("progress",f),d.readAsText(a,c)},function(){d.abort()})}function n(a){var c=new g;return new b.Promise(function(b,d,e){c.addEventListener("load",b),c.addEventListener("error",d),c.addEventListener("progress",e),c.readAsArrayBuffer(a)},function(){c.abort()})}function o(a){var c=new g;return new b.Promise(function(b,d,e){c.addEventListener("load",b),c.addEventListener("error",d),c.addEventListener("progress",e),c.readAsDataURL(a)},function(){c.abort()})}function p(a){var b,c,d,e,f;if(void 0===a)return void 0;if(a.constructor===Object){for(c=Object.keys(a).sort(),f=[],d=0;d<c.length;d+=1)b=c[d],e=p(a[b]),void 0!==e&&f.push(p(b)+":"+e);return"{"+f.join(",")+"}"}if(a.constructor===Array){for(f=[],d=0;d<a.length;d+=1)f.push(p(a[d]));return"["+f.join(",")+"]"}return JSON.stringify(a)}function q(a){if("data:"===a)return new c;var b,d=f(a.split(",")[1]),e=a.split(",")[0].split(":")[1],g=new h(d.length),j=new i(g);for(e=e.slice(0,e.length-";base64".length),b=0;b<d.length;b+=1)j[b]=d.charCodeAt(b);return new c([g],{type:e})}function r(a,b,c){if("string"!=typeof a[0]||""===a[0])throw new w.util.jIOError("Document id must be a non empty string on '"+b.__type+"."+c+"'.",400)}function s(a,b,c){if("string"!=typeof a[1]||""===a[1])throw new w.util.jIOError("Attachment id must be a non empty string on '"+b.__type+"."+c+"'.",400)}function t(a,c,d,e){return a.prototype[c]=function(){var a,f=arguments,g=this;return(new b.Queue).push(function(){return void 0!==d?d.apply(g.__storage,[f,g,c]):void 0}).push(function(b){var d=g.__storage[c];if(a=b,void 0===d)throw new w.util.jIOError("Capacity '"+c+"' is not implemented on '"+g.__type+"'",501);return d.apply(g.__storage,f)}).push(function(b){return void 0!==e?e.call(g,f,b,a):b})},this}function u(a,b){return this instanceof u?(this.__type=a,void(this.__storage=b)):new u}function v(){return this instanceof v?void(this.__storage_types={}):new v}void 0===a.openDatabase&&(a.openDatabase=function(){throw new Error("WebSQL is not supported by "+j.userAgent)});var w,x={};k.prototype=new Error,k.prototype.constructor=k,x.jIOError=k,x.ajax=l,x.readBlobAsText=m,x.readBlobAsArrayBuffer=n,x.readBlobAsDataURL=o,x.stringify=p,x.dataURItoBlob=q,t(u,"put",r,function(a){return a[0]}),t(u,"get",r),t(u,"bulk"),t(u,"remove",r,function(a){return a[0]}),u.prototype.post=function(){var a=this,c=arguments;return(new b.Queue).push(function(){var b=a.__storage.post;if(void 0===b)throw new w.util.jIOError("Capacity 'post' is not implemented on '"+a.__type+"'",501);return a.__storage.post.apply(a.__storage,c)})},t(u,"putAttachment",function(a,b,d){r(a,b,d),s(a,b,d);var e=a[3]||{};if("string"==typeof a[2])a[2]=new c([a[2]],{type:e._content_type||e._mimetype||"text/plain;charset=utf-8"});else if(!(a[2]instanceof c))throw new w.util.jIOError("Attachment content is not a blob",400)}),t(u,"removeAttachment",function(a,b,c){r(a,b,c),s(a,b,c)}),t(u,"getAttachment",function(a,b,c){var d="blob";return r(a,b,c),s(a,b,c),void 0!==a[2]&&(d=a[2].format||d,delete a[2].format),d},function(a,d,e){var f;if(!(d instanceof c))throw new w.util.jIOError("'getAttachment' ("+a[0]+" , "+a[1]+") on '"+this.__type+"' does not return a Blob.",501);if("blob"===e)f=d;else if("data_url"===e)f=(new b.Queue).push(function(){return w.util.readBlobAsDataURL(d)}).push(function(a){return a.target.result});else if("array_buffer"===e)f=(new b.Queue).push(function(){return w.util.readBlobAsArrayBuffer(d)}).push(function(a){return a.target.result});else if("text"===e)f=(new b.Queue).push(function(){return w.util.readBlobAsText(d)}).push(function(a){return a.target.result});else{if("json"!==e)throw new w.util.jIOError(this.__type+".getAttachment format: '"+e+"' is not supported",400);f=(new b.Queue).push(function(){return w.util.readBlobAsText(d)}).push(function(a){return JSON.parse(a.target.result)})}return f}),u.prototype.buildQuery=function(){var a=this.__storage.buildQuery,c=this,d=arguments;if(void 0===a)throw new w.util.jIOError("Capacity 'buildQuery' is not implemented on '"+this.__type+"'",501);return(new b.Queue).push(function(){return a.apply(c.__storage,d)})},u.prototype.hasCapacity=function(a){var b=this.__storage.hasCapacity,c=this.__storage[a];if(void 0!==c)return!0;if(void 0===b||!b.apply(this.__storage,arguments))throw new w.util.jIOError("Capacity '"+a+"' is not implemented on '"+this.__type+"'",501);return!0},u.prototype.allDocs=function(a){var c=this;return void 0===a&&(a={}),(new b.Queue).push(function(){return!c.hasCapacity("list")||void 0!==a.query&&!c.hasCapacity("query")||void 0!==a.sort_on&&!c.hasCapacity("sort")||void 0!==a.select_list&&!c.hasCapacity("select")||void 0!==a.include_docs&&!c.hasCapacity("include")||void 0!==a.limit&&!c.hasCapacity("limit")?void 0:c.buildQuery(a)}).push(function(a){return{data:{rows:a,total_rows:a.length}}})},t(u,"allAttachments",r),t(u,"repair"),u.prototype.repair=function(){var a=this,c=arguments;return(new b.Queue).push(function(){var b=a.__storage.repair;return void 0!==b?a.__storage.repair.apply(a.__storage,c):void 0})},v.prototype.createJIO=function(a,b){if("string"!=typeof a.type)throw new TypeError("Invalid storage description");if(!this.__storage_types[a.type])throw new TypeError("Unknown storage '"+a.type+"'");return new u(a.type,new this.__storage_types[a.type](a,b))},v.prototype.addStorage=function(a,b){if("string"!=typeof a)throw new TypeError("jIO.addStorage(): Argument 1 is not of type 'string'");if("function"!=typeof b)throw new TypeError("jIO.addStorage(): Argument 2 is not of type 'function'");if(void 0!==this.__storage_types[a])throw new TypeError("jIO.addStorage(): Storage type already exists");this.__storage_types[a]=b},v.prototype.util=x,v.prototype.QueryFactory=d,v.prototype.Query=e,w=new v,a.jIO=w}(window,RSVP,Blob,QueryFactory,Query,atob,FileReader,ArrayBuffer,Uint8Array,navigator),function(a,b,c,d){"use strict";function e(a){return h.digestFromString(a)}function f(a){return h.digestFromArrayBuffer(a)}function g(b){if(this._query_options=b.query||{},this._local_sub_storage=a.createJIO(b.local_sub_storage),this._remote_sub_storage=a.createJIO(b.remote_sub_storage),this._signature_hash="_replicate_"+e(d(b.local_sub_storage)+d(b.remote_sub_storage)+d(this._query_options)),this._signature_sub_storage=a.createJIO({type:"document",document_id:this._signature_hash,sub_storage:b.signature_storage||b.local_sub_storage}),this._use_remote_post=b.use_remote_post||!1,this._conflict_handling=b.conflict_handling||0,this._conflict_handling!==i&&this._conflict_handling!==j&&this._conflict_handling!==k&&this._conflict_handling!==l)throw new a.util.jIOError("Unsupported conflict handling: "+this._conflict_handling,400);this._check_local_modification=b.check_local_modification,void 0===this._check_local_modification&&(this._check_local_modification=!0),this._check_local_creation=b.check_local_creation,void 0===this._check_local_creation&&(this._check_local_creation=!0),this._check_local_deletion=b.check_local_deletion,void 0===this._check_local_deletion&&(this._check_local_deletion=!0),this._check_remote_modification=b.check_remote_modification,void 0===this._check_remote_modification&&(this._check_remote_modification=!0),this._check_remote_creation=b.check_remote_creation,void 0===this._check_remote_creation&&(this._check_remote_creation=!0),this._check_remote_deletion=b.check_remote_deletion,void 0===this._check_remote_deletion&&(this._check_remote_deletion=!0),this._check_local_attachment_modification=b.check_local_attachment_modification,void 0===this._check_local_attachment_modification&&(this._check_local_attachment_modification=!1),this._check_local_attachment_creation=b.check_local_attachment_creation,void 0===this._check_local_attachment_creation&&(this._check_local_attachment_creation=!1),this._check_local_attachment_deletion=b.check_local_attachment_deletion,void 0===this._check_local_attachment_deletion&&(this._check_local_attachment_deletion=!1),this._check_remote_attachment_modification=b.check_remote_attachment_modification,void 0===this._check_remote_attachment_modification&&(this._check_remote_attachment_modification=!1),this._check_remote_attachment_creation=b.check_remote_attachment_creation,void 0===this._check_remote_attachment_creation&&(this._check_remote_attachment_creation=!1),this._check_remote_attachment_deletion=b.check_remote_attachment_deletion,void 0===this._check_remote_attachment_deletion&&(this._check_remote_attachment_deletion=!1)}var h=new c,i=0,j=1,k=2,l=3;g.prototype.remove=function(b){if(b===this._signature_hash)throw new a.util.jIOError(this._signature_hash+" is frozen",403);return this._local_sub_storage.remove.apply(this._local_sub_storage,arguments)},g.prototype.post=function(){return this._local_sub_storage.post.apply(this._local_sub_storage,arguments)},g.prototype.put=function(b){if(b===this._signature_hash)throw new a.util.jIOError(this._signature_hash+" is frozen",403);return this._local_sub_storage.put.apply(this._local_sub_storage,arguments)},g.prototype.get=function(){return this._local_sub_storage.get.apply(this._local_sub_storage,arguments)},g.prototype.getAttachment=function(){return this._local_sub_storage.getAttachment.apply(this._local_sub_storage,arguments)},g.prototype.allAttachments=function(){return this._local_sub_storage.allAttachments.apply(this._local_sub_storage,arguments)},g.prototype.putAttachment=function(b){if(b===this._signature_hash)throw new a.util.jIOError(this._signature_hash+" is frozen",403);return this._local_sub_storage.putAttachment.apply(this._local_sub_storage,arguments)},g.prototype.removeAttachment=function(b){if(b===this._signature_hash)throw new a.util.jIOError(this._signature_hash+" is frozen",403);return this._local_sub_storage.removeAttachment.apply(this._local_sub_storage,arguments)},g.prototype.hasCapacity=function(){return this._local_sub_storage.hasCapacity.apply(this._local_sub_storage,arguments);
},g.prototype.buildQuery=function(){return this._local_sub_storage.buildQuery.apply(this._local_sub_storage,arguments)},g.prototype.repair=function(){function c(a,b,c,d){return b.removeAttachment(c,d).push(function(){return w._signature_sub_storage.removeAttachment(c,d)}).push(function(){a[d]=null})}function g(a,b,c,d,e,f){return b.putAttachment(e,f,c).push(function(){return w._signature_sub_storage.putAttachment(e,f,JSON.stringify({hash:d}))}).push(function(){a[f]=null})}function h(b,d,e,h,i,j,k,l,m,n,o){var p;return j.getAttachment(k,l).push(function(b){return p=b,a.util.readBlobAsArrayBuffer(p)}).push(function(a){return f(a.target.result)},function(b){if(b instanceof a.util.jIOError&&404===b.status_code)return p=null,null;throw b}).push(function(f){if(e===f)return null===e?w._signature_sub_storage.removeAttachment(k,l).push(function(){b[k]=null}):w._signature_sub_storage.putAttachment(k,l,JSON.stringify({hash:e})).push(function(){y[k]=null});if(f===d||m===!0)return null===e?c(b,j,k,l):g(b,j,h,e,k,l);if(o!==!0){if(n===!0||null===e)return null===f?c(b,i,k,l):g(b,i,p,f,k,l);if(null===f)return g(b,j,h,e,k,l);throw new a.util.jIOError("Conflict on '"+k+"' with attachment '"+l+"'",409)}})}function i(c,d,e,g,i,j,k,l,m,n,o){var p,q;d.push(function(){if(n===!0)return b.all([e.getAttachment(i,j),{hash:null}]);if(o===!0)return b.all([e.getAttachment(i,j),w._signature_sub_storage.getAttachment(i,j,{format:"json"})]);throw new a.util.jIOError("Unexpected call of checkAttachmentSignatureDifference",409)}).push(function(b){return p=b[0],q=b[1].hash,a.util.readBlobAsArrayBuffer(p)}).push(function(a){var b=a.target.result,d=f(b);return d!==q?h(c,q,d,p,e,g,i,j,k,l,m):void 0})}function m(a,b,c,d,e,f,g,i,j){var k;b.push(function(){return w._signature_sub_storage.getAttachment(d,e,{format:"json"})}).push(function(b){return k=b.hash,h(a,k,null,null,f,c,d,e,g,i,j)})}function n(c,d,e,f,g){var h=new b.Queue;return h.push(function(){return b.all([e.allAttachments(d).push(void 0,function(b){if(b instanceof a.util.jIOError&&404===b.status_code)return{};throw b}),w._signature_sub_storage.allAttachments(d).push(void 0,function(b){if(b instanceof a.util.jIOError&&404===b.status_code)return{};throw b})])}).push(function(a){var b,j,k,l={},n={};for(k in a[0])a[0].hasOwnProperty(k)&&(c.hasOwnProperty(k)||(l[k]=null));for(k in a[1])a[1].hasOwnProperty(k)&&(c.hasOwnProperty(k)||(n[k]=null));for(k in l)l.hasOwnProperty(k)&&(b=n.hasOwnProperty(k)&&g.check_modification,j=!n.hasOwnProperty(k)&&g.check_creation,(b===!0||j===!0)&&i(c,h,e,f,d,k,g.conflict_force,g.conflict_revert,g.conflict_ignore,j,b));if(g.check_deletion===!0)for(k in n)n.hasOwnProperty(k)&&(l.hasOwnProperty(k)||m(c,h,f,d,k,e,g.conflict_force,g.conflict_revert,g.conflict_ignore))})}function o(a){var c={};return(new b.Queue).push(function(){return w._check_local_attachment_modification||w._check_local_attachment_creation||w._check_local_attachment_deletion?n(c,a,w._local_sub_storage,w._remote_sub_storage,{conflict_force:w._conflict_handling===j,conflict_revert:w._conflict_handling===k,conflict_ignore:w._conflict_handling===l,check_modification:w._check_local_attachment_modification,check_creation:w._check_local_attachment_creation,check_deletion:w._check_local_attachment_deletion}):void 0}).push(function(){return w._check_remote_attachment_modification||w._check_remote_attachment_creation||w._check_remote_attachment_deletion?n(c,a,w._remote_sub_storage,w._local_sub_storage,{use_revert_post:w._use_remote_post,conflict_force:w._conflict_handling===k,conflict_revert:w._conflict_handling===j,conflict_ignore:w._conflict_handling===l,check_modification:w._check_remote_attachment_modification,check_creation:w._check_remote_attachment_creation,check_deletion:w._check_remote_attachment_deletion}):void 0})}function p(a,c,d,e,f,g){var h,i,j=!0;return void 0===g&&(g={}),h=g.use_post?c.post(d).push(function(b){return j=!1,i=b,a.put(i,d)}).push(function(){return a.allAttachments(f)}).push(function(c){function d(b){g.push(function(){return a.getAttachment(f,b)}).push(function(c){return a.putAttachment(i,b,c)})}var e,g=new b.Queue;for(e in c)c.hasOwnProperty(e)&&d(e);return g}).push(function(){return a.remove(f)}).push(function(){return w._signature_sub_storage.remove(f)}).push(function(){return j=!0,w._signature_sub_storage.put(i,{hash:e})}).push(function(){y[i]=null}):c.put(f,d).push(function(){return w._signature_sub_storage.put(f,{hash:e})}),h.push(function(){j&&(y[f]=null)})}function q(b,c){return o(c).push(function(){return b.allAttachments(c)}).push(function(a){return"{}"===JSON.stringify(a)?b.remove(c).push(function(){return w._signature_sub_storage.remove(c)}):void 0},function(b){if(!(b instanceof a.util.jIOError&&404===b.status_code))throw b}).push(function(){y[c]=null})}function r(b,c,f,g,h,i,j,k,l,m){return h.get(i).push(function(a){return[a,e(d(a))]},function(b){if(b instanceof a.util.jIOError&&404===b.status_code)return[null,null];throw b}).push(function(e){var n=e[0],o=e[1];if(c===o)return null===c?w._signature_sub_storage.remove(i).push(function(){y[i]=null}):w._signature_sub_storage.put(i,{hash:c}).push(function(){y[i]=null});if(o===b||j===!0)return null===c?q(h,i):p(g,h,f,c,i,{use_post:m.use_post&&null===o});if(l!==!0){if(k===!0||null===c)return null===o?q(g,i):p(h,g,n,o,i,{use_post:m.use_revert_post&&null===c});if(null===o)return p(g,h,f,c,i,{use_post:m.use_post});throw new a.util.jIOError("Conflict on '"+i+"': "+d(f||"")+" !== "+d(n||""),409)}})}function s(a,b,c,d,e,f,g,h){var i;a.push(function(){return w._signature_sub_storage.get(c)}).push(function(a){return i=a.hash,r(i,null,null,d,b,c,e,f,g,h)})}function t(c,f,g,h,i,j,k,l,m,n,o){c.push(function(){if(l===!0)return b.all([n(h),{hash:null}]);if(m===!0)return b.all([n(h),w._signature_sub_storage.get(h)]);throw new a.util.jIOError("Unexpected call of checkSignatureDifference",409)}).push(function(a){var b=a[0],c=e(d(b)),l=a[1].hash;return c!==l?r(l,c,b,f,g,h,i,j,k,o):void 0})}function u(a,c,d,e,f,g,h,i,j){a.push(function(){return c.bulk(e)}).push(function(a){function k(b){return function(c){if(c!==e[b].parameter_list[0])throw new Error("Does not access expected ID "+c);return a[b]}}var l,m=new b.Queue;for(l=0;l<a.length;l+=1)t(m,c,d,e[l].parameter_list[0],h,i,j,f[l].is_creation,f[l].is_modification,k(l),g);return m})}function v(a,c,d){var e=new b.Queue;return d.hasOwnProperty("use_post")||(d.use_post=!1),d.hasOwnProperty("use_revert_post")||(d.use_revert_post=!1),e.push(function(){return b.all([a.allDocs(w._query_options),w._signature_sub_storage.allDocs()])}).push(function(b){var f,g,h,i,j={},k=[],l=[],m={};for(f=0;f<b[0].data.total_rows;f+=1)y.hasOwnProperty(b[0].data.rows[f].id)||(j[b[0].data.rows[f].id]=f);for(f=0;f<b[1].data.total_rows;f+=1)y.hasOwnProperty(b[1].data.rows[f].id)||(m[b[1].data.rows[f].id]=f);for(i in j)j.hasOwnProperty(i)&&(g=m.hasOwnProperty(i)&&d.check_modification,h=!m.hasOwnProperty(i)&&d.check_creation,(g===!0||h===!0)&&(d.use_bulk_get===!0?(k.push({method:"get",parameter_list:[i]}),l.push({is_creation:h,is_modification:g})):t(e,a,c,i,d.conflict_force,d.conflict_revert,d.conflict_ignore,h,g,a.get.bind(a),d)));if(d.check_deletion===!0)for(i in m)m.hasOwnProperty(i)&&(j.hasOwnProperty(i)||s(e,c,i,a,d.conflict_force,d.conflict_revert,d.conflict_ignore,d));d.use_bulk_get===!0&&0!==k.length&&u(e,a,c,k,l,d,d.conflict_force,d.conflict_revert,d.conflict_ignore)})}var w=this,x=arguments,y={};return y[w._signature_hash]=null,(new b.Queue).push(function(){return w._signature_sub_storage.__storage._sub_storage.get(w._signature_hash)}).push(void 0,function(b){if(b instanceof a.util.jIOError&&404===b.status_code)return w._signature_sub_storage.__storage._sub_storage.put(w._signature_hash,{});throw b}).push(function(){return b.all([w._local_sub_storage.repair.apply(w._local_sub_storage,x),w._remote_sub_storage.repair.apply(w._remote_sub_storage,x)])}).push(function(){return w._check_local_modification||w._check_local_creation||w._check_local_deletion?v(w._local_sub_storage,w._remote_sub_storage,{use_post:w._use_remote_post,conflict_force:w._conflict_handling===j,conflict_revert:w._conflict_handling===k,conflict_ignore:w._conflict_handling===l,check_modification:w._check_local_modification,check_creation:w._check_local_creation,check_deletion:w._check_local_deletion}):void 0}).push(function(){var b=!1;try{b=w._remote_sub_storage.hasCapacity("bulk_get")}catch(c){if(!(c instanceof a.util.jIOError&&501===c.status_code))throw c}return w._check_remote_modification||w._check_remote_creation||w._check_remote_deletion?v(w._remote_sub_storage,w._local_sub_storage,{use_bulk_get:b,use_revert_post:w._use_remote_post,conflict_force:w._conflict_handling===k,conflict_revert:w._conflict_handling===j,conflict_ignore:w._conflict_handling===l,check_modification:w._check_remote_modification,check_creation:w._check_remote_creation,check_deletion:w._check_remote_deletion}):void 0}).push(function(){return w._check_local_attachment_modification||w._check_local_attachment_creation||w._check_local_attachment_deletion||w._check_remote_attachment_modification||w._check_remote_attachment_creation||w._check_remote_attachment_deletion?w._signature_sub_storage.allDocs().push(function(a){function c(a){e.push(function(){return o(a)})}var d,e=new b.Queue;for(d=0;d<a.data.total_rows;d+=1)c(a.data.rows[d].id);return e}):void 0})},a.addStorage("replicate",g)}(jIO,RSVP,Rusha,jIO.util.stringify),function(a){"use strict";function b(b){this._sub_storage=a.createJIO(b.sub_storage)}b.prototype.get=function(){return this._sub_storage.get.apply(this._sub_storage,arguments)},b.prototype.allAttachments=function(){return this._sub_storage.allAttachments.apply(this._sub_storage,arguments)},b.prototype.post=function(a){function b(){return("0000"+Math.floor(65536*Math.random()).toString(16)).slice(-4)}var c=b()+b()+"-"+b()+"-"+b()+"-"+b()+"-"+b()+b()+b();return this.put(c,a)},b.prototype.put=function(){return this._sub_storage.put.apply(this._sub_storage,arguments)},b.prototype.remove=function(){return this._sub_storage.remove.apply(this._sub_storage,arguments)},b.prototype.getAttachment=function(){return this._sub_storage.getAttachment.apply(this._sub_storage,arguments)},b.prototype.putAttachment=function(){return this._sub_storage.putAttachment.apply(this._sub_storage,arguments)},b.prototype.removeAttachment=function(){return this._sub_storage.removeAttachment.apply(this._sub_storage,arguments)},b.prototype.repair=function(){return this._sub_storage.repair.apply(this._sub_storage,arguments)},b.prototype.hasCapacity=function(a){return this._sub_storage.hasCapacity(a)},b.prototype.buildQuery=function(){return this._sub_storage.buildQuery.apply(this._sub_storage,arguments)},a.addStorage("uuid",b)}(jIO),function(a,b,c){"use strict";function d(){this._database={}}d.prototype.put=function(a,c){return this._database.hasOwnProperty(a)||(this._database[a]={attachments:{}}),this._database[a].doc=b.stringify(c),a},d.prototype.get=function(c){try{return b.parse(this._database[c].doc)}catch(d){if(d instanceof TypeError)throw new a.util.jIOError("Cannot find document: "+c,404);throw d}},d.prototype.allAttachments=function(b){var c,d={};try{for(c in this._database[b].attachments)this._database[b].attachments.hasOwnProperty(c)&&(d[c]={})}catch(e){if(e instanceof TypeError)throw new a.util.jIOError("Cannot find document: "+b,404);throw e}return d},d.prototype.remove=function(a){return delete this._database[a],a},d.prototype.getAttachment=function(b,c){try{var d=this._database[b].attachments[c];if(void 0===d)throw new a.util.jIOError("Cannot find attachment: "+b+" , "+c,404);return a.util.dataURItoBlob(d)}catch(e){if(e instanceof TypeError)throw new a.util.jIOError("Cannot find attachment: "+b+" , "+c,404);throw e}},d.prototype.putAttachment=function(b,d,e){var f;try{f=this._database[b].attachments}catch(g){if(g instanceof TypeError)throw new a.util.jIOError("Cannot find document: "+b,404);throw g}return(new c.Queue).push(function(){return a.util.readBlobAsDataURL(e)}).push(function(a){f[d]=a.target.result})},d.prototype.removeAttachment=function(b,c){try{delete this._database[b].attachments[c]}catch(d){if(d instanceof TypeError)throw new a.util.jIOError("Cannot find document: "+b,404);throw d}},d.prototype.hasCapacity=function(a){return"list"===a||"include"===a},d.prototype.buildQuery=function(a){var c,d=[];for(c in this._database)this._database.hasOwnProperty(c)&&(a.include_docs===!0?d.push({id:c,value:{},doc:b.parse(this._database[c].doc)}):d.push({id:c,value:{}}));return d},a.addStorage("memory",d)}(jIO,JSON,RSVP),function(a,b,c,d,e,f,g,h){"use strict";function i(b){return(new d.Queue).push(function(){return a.util.ajax({type:"GET",url:b._url,xhrFields:{withCredentials:b._thisCredentials},headers:b._headers})}).push(function(a){return JSON.parse(a.target.responseText)})}function j(c,e,f){return void 0===f&&(f={}),i(c).push(function(g){return(new d.Queue).push(function(){return a.util.ajax({type:"GET",url:b.parse(g._links.traverse.href).expand({relative_url:e,view:f._view}),xhrFields:{withCredentials:c._thisCredentials},headers:c._headers})}).push(void 0,function(b){if(void 0!==b.target&&404===b.target.status)throw new a.util.jIOError("Cannot find document: "+e,404);throw b})})}function k(a){return(new d.Queue).push(function(){var b,c,d,f,g=a._embedded._view,h={portal_type:a._links.type.name},i={};a._links.hasOwnProperty("parent")&&(h.parent_relative_url=new e(a._links.parent.href).segment(2)),i.form_id={key:[g.form_id.key],"default":g.form_id["default"]};for(c in g)g.hasOwnProperty(c)&&(b=g[c],d=0,0===c.indexOf("my_")&&b.editable&&(d=3),0===c.indexOf("your_")&&(d=5),0!==d&&q.hasOwnProperty(b.type)&&(i[c.substring(d)]={"default":b["default"],key:b.key},h[c.substring(d)]=b["default"]));return f={data:h,form_data:i},g.hasOwnProperty("_actions")&&g._actions.hasOwnProperty("put")&&(f.action_href=g._actions.put.href),f})}function l(b,c){return b.getAttachment(c,"view").push(function(b){return a.util.readBlobAsText(b)}).push(function(a){return JSON.parse(a.target.result)}).push(function(a){return k(a)})}function m(a){if("string"!=typeof a.url||!a.url)throw new TypeError("ERP5 'url' must be a string which contains more than one character.");this._url=a.url,this._default_view_reference=a.default_view_reference,this._headers=null,this._thisCredentials=!0,void 0!==a.login&&void 0!==a.password&&(this._headers={Authorization:"Basic "+btoa(a.login+":"+a.password)},this._thisCredentials=!1)}function n(a){return a.data}function o(a){return a instanceof g&&"local_roles"===a.key?a.value:void 0}function p(a){var b,c,d=!0,e=[];if(a instanceof h&&"OR"===a.operator){for(b=0;b<a.query_list.length;b+=1)c=a.query_list[b],c instanceof g&&"local_roles"===c.key?e.push(c.value):d=!1;if(d)return e}}var q={StringField:null,EmailField:null,IntegerField:null,FloatField:null,TextAreaField:null};m.prototype.get=function(a){return l(this,a).push(function(a){return n(a)})},m.prototype.bulk=function(b){var e,f=this,g=[];for(e=0;e<b.length;e+=1){if("get"!==b[e].method)throw new Error("ERP5Storage: not supported "+b[e].method+" in bulk");g.push({relative_url:b[e].parameter_list[0],view:f._default_view_reference})}return i(f).push(function(b){var d=new c;return d.append("bulk_list",JSON.stringify(g)),a.util.ajax({type:"POST",url:b._actions.bulk.href,data:d,xhrFields:{withCredentials:f._thisCredentials},headers:f._headers})}).push(function(a){function b(a){return k(a).push(function(a){return n(a)})}var c=[],f=JSON.parse(a.target.responseText);for(e=0;e<f.result_list.length;e+=1)c.push(b(f.result_list[e]));return d.all(c)})},m.prototype.post=function(b){var d,f=this;return i(this).push(function(d){var e=new c;return e.append("portal_type",b.portal_type),e.append("parent_relative_url",b.parent_relative_url),a.util.ajax({type:"POST",url:d._actions.add.href,data:e,xhrFields:{withCredentials:f._thisCredentials},headers:f._headers})}).push(function(a){var c=a.target.getResponseHeader("X-Location"),g=new e(c);return d=g.segment(2),f.put(d,b)}).push(function(){return d})},m.prototype.put=function(b,c){var d=this;return l(d,b).push(function(e){var g,h=e.form_data,i={};i[h.form_id.key]=h.form_id["default"];for(g in c)if(c.hasOwnProperty(g)){if("form_id"===g)throw new a.util.jIOError("ERP5: forbidden property: "+g,400);if("portal_type"!==g&&"parent_relative_url"!==g){if(!h.hasOwnProperty(g))throw new a.util.jIOError("ERP5: can not store property: "+g,400);i[h[g].key]=c[g]}}if(!e.hasOwnProperty("action_href"))throw new a.util.jIOError("ERP5: can not modify document: "+b,403);return d.putAttachment(b,e.action_href,new f([JSON.stringify(i)],{type:"application/json"}))})},m.prototype.allAttachments=function(a){var b=this;return j(this,a).push(function(){return void 0===b._default_view_reference?{links:{}}:{view:{},links:{}}})},m.prototype.getAttachment=function(b,c,e){var g=this;if(void 0===e&&(e={}),"view"===c){if(void 0===this._default_view_reference)throw new a.util.jIOError("Cannot find attachment view for: "+b,404);return j(this,b,{_view:this._default_view_reference}).push(function(a){var b=JSON.parse(a.target.responseText);return new f([JSON.stringify(b)],{type:"application/hal+json"})})}if("links"===c)return j(this,b).push(function(a){return new f([JSON.stringify(JSON.parse(a.target.responseText))],{type:"application/hal+json"})});if(0===c.indexOf(this._url))return(new d.Queue).push(function(){var b,d,f,h={type:"GET",dataType:"blob",url:c,xhrFields:{withCredentials:g._thisCredentials},headers:g._headers};if(void 0!==e.start||void 0!==e.end){if(b=e.start||0,d=e.end,void 0!==d&&0>d)throw new a.util.jIOError("end must be positive",400);if(0>b)f="bytes="+b;else if(void 0===d)f="bytes="+b+"-";else{if(b>d)throw new a.util.jIOError("start is greater than end",400);f="bytes="+b+"-"+d}void 0===g._headers?h.headers={Range:f}:h.headers.Range=f}return a.util.ajax(h)}).push(function(a){return void 0===a.target.response?new f([a.target.responseText],{type:a.target.getResponseHeader("Content-Type")}):a.target.response});throw new a.util.jIOError("ERP5: not support get attachment: "+c,400)},m.prototype.putAttachment=function(b,e,f){var g=this;if(0!==e.indexOf(this._url))throw new a.util.jIOError("Can not store outside ERP5: "+e,400);return(new d.Queue).push(function(){return a.util.readBlobAsText(f)}).push(function(b){var d,f,h,i,j=JSON.parse(b.target.result),k=new c;for(h in j)if(j.hasOwnProperty(h))for(d=Array.isArray(j[h])?j[h]:[j[h]],f=0;f<d.length;f+=1)i=d[f],"object"==typeof i?k.append(h,a.util.dataURItoBlob(i.url),i.file_name):k.append(h,i);return a.util.ajax({type:"POST",url:e,data:k,xhrFields:{withCredentials:g._thisCredentials},headers:g._headers})})},m.prototype.hasCapacity=function(a){return"list"===a||"query"===a||"select"===a||"limit"===a||"sort"===a||"bulk_get"===a},m.prototype.buildQuery=function(c){var d=this;return i(this).push(function(e){var f,g,i,j,k,l=c.query,m=[];if(c.query)if(g=a.QueryFactory.create(c.query),j=o(g))l=void 0,k=j;else if(j=p(g))l=void 0,k=j;else if(g instanceof h&&"AND"===g.operator)for(f=0;f<g.query_list.length;f+=1)i=g.query_list[f],j=o(i),j?(k=j,g.query_list.splice(f,1),l=a.Query.objectToSearchText(g),f=g.query_list.length):(j=p(i),j&&(k=j,g.query_list.splice(f,1),l=a.Query.objectToSearchText(g),f=g.query_list.length));if(c.sort_on)for(f=0;f<c.sort_on.length;f+=1)m.push(JSON.stringify(c.sort_on[f]));return a.util.ajax({type:"GET",url:b.parse(e._links.raw_search.href).expand({query:l,select_list:c.select_list||["title","reference"],limit:c.limit,sort_on:m,local_roles:k}),xhrFields:{withCredentials:d._thisCredentials},headers:d._headers})}).push(function(a){return JSON.parse(a.target.responseText)}).push(function(a){var b,c,d,f=a._embedded.contents,g=f.length,h=[];for(b=0;g>b;b+=1)d=f[b],c=new e(d._links.self.href),delete d._links,h.push({id:c.segment(2),value:d});return h})},a.addStorage("erp5",m)}(jIO,UriTemplate,FormData,RSVP,URI,Blob,SimpleQuery,ComplexQuery),function(a,b,c,d,e){"use strict";function f(b){this._sub_storage=a.createJIO(b.sub_storage),this._document_id=b.document_id,this._repair_attachment=b.repair_attachment||!1}function g(a,b){return void 0===b?"jio_document/"+d(a)+h:"jio_attachment/"+d(a)+"/"+d(b)}var h=".json",i=new RegExp("^jio_document/([\\w=]+)"+h+"$"),j=new RegExp("^jio_attachment/([\\w=]+)/([\\w=]+)$");f.prototype.get=function(a){return this._sub_storage.getAttachment(this._document_id,g(a),{format:"json"})},f.prototype.allAttachments=function(a){return this._sub_storage.allAttachments(this._document_id).push(function(b){var d,e,f={};for(e in b)if(b.hasOwnProperty(e)&&j.test(e)){d=j.exec(e);try{c(d[1])===a&&(f[c(d[2])]={})}catch(g){if(!g instanceof ReferenceError)throw g}}return f})},f.prototype.put=function(a,c){return this._sub_storage.putAttachment(this._document_id,g(a),new b([JSON.stringify(c)],{type:"application/json"})).push(function(){return a})},f.prototype.remove=function(a){var b=this;return this.allAttachments(a).push(function(c){var d,f=[];for(d in c)c.hasOwnProperty(d)&&f.push(b.removeAttachment(a,d));return e.all(f)}).push(function(){return b._sub_storage.removeAttachment(b._document_id,g(a))}).push(function(){return a})},f.prototype.repair=function(){var a=this;return this._sub_storage.repair.apply(this._sub_storage,arguments).push(function(b){return a._repair_attachment?a._sub_storage.allAttachments(a._document_id).push(function(b){var d,f,g,h,k=[],l={},m={};for(h in b)if(b.hasOwnProperty(h))if(d=void 0,f=void 0,i.test(h)){try{d=c(i.exec(h)[1])}catch(n){if(!n instanceof ReferenceError)throw n}void 0!==d&&(l[d]=null)}else if(j.test(h)){g=j.exec(h);try{d=c(g[1]),f=c(g[2])}catch(n){if(!n instanceof ReferenceError)throw n}void 0!==f&&(l.hasOwnProperty(d)||(m.hasOwnProperty(d)||(m[d]={}),m[d][f]=null))}for(d in m)if(m.hasOwnProperty(d)&&!l.hasOwnProperty(d))for(f in m[d])m[d].hasOwnProperty(f)&&k.push(a.removeAttachment(d,f));return e.all(k)}):b})},f.prototype.hasCapacity=function(a){return"list"===a},f.prototype.buildQuery=function(){return this._sub_storage.allAttachments(this._document_id).push(function(a){var b,d=[];for(b in a)if(a.hasOwnProperty(b)&&i.test(b))try{d.push({id:c(i.exec(b)[1]),value:{}})}catch(e){if(!e instanceof ReferenceError)throw e}return d})},f.prototype.getAttachment=function(a,b){return this._sub_storage.getAttachment(this._document_id,g(a,b))},f.prototype.putAttachment=function(a,b,c){return this._sub_storage.putAttachment(this._document_id,g(a,b),c)},f.prototype.removeAttachment=function(a,b){return this._sub_storage.removeAttachment(this._document_id,g(a,b))},a.addStorage("document",f)}(jIO,Blob,atob,btoa,RSVP),function(a,b){"use strict";function c(b){this._sub_storage=a.createJIO(b.sub_storage),this._key_schema=b.key_schema}c.prototype.get=function(){return this._sub_storage.get.apply(this._sub_storage,arguments)},c.prototype.allAttachments=function(){return this._sub_storage.allAttachments.apply(this._sub_storage,arguments)},c.prototype.post=function(){return this._sub_storage.post.apply(this._sub_storage,arguments)},c.prototype.put=function(){return this._sub_storage.put.apply(this._sub_storage,arguments)},c.prototype.remove=function(){return this._sub_storage.remove.apply(this._sub_storage,arguments)},c.prototype.getAttachment=function(){return this._sub_storage.getAttachment.apply(this._sub_storage,arguments)},c.prototype.putAttachment=function(){return this._sub_storage.putAttachment.apply(this._sub_storage,arguments)},c.prototype.removeAttachment=function(){return this._sub_storage.removeAttachment.apply(this._sub_storage,arguments)},c.prototype.repair=function(){return this._sub_storage.repair.apply(this._sub_storage,arguments)},c.prototype.hasCapacity=function(a){var b=["limit","sort","select","query"];return-1!==b.indexOf(a)?!0:"list"===a?this._sub_storage.hasCapacity(a):!1},c.prototype.buildQuery=function(c){var d=this._sub_storage,e=this,f={},g=!1,h=!1;if(d.hasCapacity("list")){try{void 0!==c.query&&!d.hasCapacity("query")||void 0!==c.sort_on&&!d.hasCapacity("sort")||void 0!==c.select_list&&!d.hasCapacity("select")||void 0!==c.limit&&!d.hasCapacity("limit")||(f.query=c.query,f.sort_on=c.sort_on,f.select_list=c.select_list,f.limit=c.limit)}catch(i){if(!(i instanceof a.util.jIOError&&501===i.status_code))throw i;g=!0}try{(g||c.include_docs===!0)&&d.hasCapacity("include")&&(f.include_docs=!0)}catch(i){if(!(i instanceof a.util.jIOError&&501===i.status_code))throw i;h=!0}return d.buildQuery(f).push(function(c){function e(b){var e=c[b].id;return d.get(e).push(function(a){return a._id=e,a},function(b){if(!(b instanceof a.util.jIOError&&404===b.status_code))throw b})}var f,g,i=[c];if(h){for(f=c.length,g=0;f>g;g+=1)i.push(e(g));c=b.all(i)}return c}).push(function(a){var b,c,d;if(h){for(b=a[0],c=b.length,d=0;c>d;d+=1)b[d].doc=a[d+1];a=b}return a}).push(function(b){var d,f,h=[];if(g){for(d=b.length,f=0;d>f;f+=1)b[f].doc.__id=b[f].id,h.push(b[f].doc);c.select_list&&c.select_list.push("__id"),b=a.QueryFactory.create(c.query||"",e._key_schema).exec(h,c)}return b}).push(function(a){var b,d,e,f=[];if(g){for(d=a.length,e=0;d>e;e+=1){if(b={id:a[e].__id,value:c.select_list?a[e]:{},doc:{}},c.select_list&&delete b.value.__id,c.include_docs)throw new Error("QueryStorage does not support include docs");f.push(b)}a=f}return a})}},a.addStorage("query",c)}(jIO,RSVP),function(a,b,c,d){"use strict";function e(a){a.sessiononly===!0?this._storage=b:this._storage=c}function f(b){if("/"!==b)throw new a.util.jIOError("id "+b+" is forbidden (!== /)",400)}e.prototype.get=function(a){return f(a),{}},e.prototype.allAttachments=function(a){f(a);var b,c={};for(b in this._storage)this._storage.hasOwnProperty(b)&&(c[b]={});return c},e.prototype.getAttachment=function(b,c){f(b);var d=this._storage.getItem(c);if(null===d)throw new a.util.jIOError("Cannot find attachment "+c,404);return a.util.dataURItoBlob(d)},e.prototype.putAttachment=function(b,c,e){var g=this;return f(b),(new d.Queue).push(function(){return a.util.readBlobAsDataURL(e)}).push(function(a){g._storage.setItem(c,a.target.result)})},e.prototype.removeAttachment=function(a,b){return f(a),this._storage.removeItem(b)},e.prototype.hasCapacity=function(a){return"list"===a},e.prototype.buildQuery=function(){return[{id:"/",value:{}}]},a.addStorage("local",e)}(jIO,sessionStorage,localStorage,RSVP),function(a,b,c,d,e,f,g){"use strict";function h(b){var c,g=[];for(c in b._mapping_dict)if(b._mapping_dict.hasOwnProperty(c)){if("equalValue"===b._mapping_dict[c][0]){if(void 0===b._mapping_dict[c][1])throw new a.util.jIOError("equalValue has not parameter",400);b._default_mapping[c]=b._mapping_dict[c][1],g.push(new d({key:c,value:b._mapping_dict[c][1],type:"simple"}))}if("equalSubId"===b._mapping_dict[c][0]){if(void 0!==b._property_for_sub_id)throw new a.util.jIOError("equalSubId can be defined one time",400);b._property_for_sub_id=c}}void 0!==b._query.query&&g.push(f.create(b._query.query)),g.length>1?b._query.query=new e({type:"complex",query_list:g,operator:"AND"}):1===g.length&&(b._query.query=g[0])}function i(b){this._mapping_dict=b.mapping_dict||{},this._sub_storage=a.createJIO(b.sub_storage),this._map_all_property=void 0!==b.map_all_property?b.map_all_property:!0,this._attachment_mapping_dict=b.attachment_mapping_dict||{},this._query=b.query||{},this._map_id=b.map_id,this._id_mapped=void 0!==b.map_id?b.map_id[1]:!1,void 0!==this._query.query&&(this._query.query=f.create(this._query.query)),this._default_mapping={},h(this)}function j(a,b,d,e){var f=a._attachment_mapping_dict;return void 0!==f&&void 0!==f[d]&&void 0!==f[d][e]&&void 0!==f[d][e].uri_template?c.parse(f[d][e].uri_template).expand({id:b}):d}function k(c,f,h){var i;return(new b.Queue).push(function(){if(void 0!==c._property_for_sub_id&&void 0!==h&&void 0!==h[c._property_for_sub_id])return h[c._property_for_sub_id];if(!c._id_mapped)return f;if("equalSubProperty"===c._map_id[0])return i=new d({key:c._map_id[1],value:f,type:"simple"}),void 0!==c._query.query&&(i=new e({operator:"AND",query_list:[i,c._query.query],type:"complex"})),i=g.objectToSearchText(i),c._sub_storage.allDocs({query:i,sort_on:c._query.sort_on,select_list:c._query.select_list,limit:c._query.limit}).push(function(b){if(0===b.data.rows.length)throw new a.util.jIOError("Can not find id",404);if(b.data.rows.length>1)throw new TypeError("id must be unique field: "+f+", result:"+b.data.rows.toString());return b.data.rows[0].id});throw new a.util.jIOError("Unsuported option: "+c._mapping_dict.id,400)})}function l(b,c,d,e){var f,g;if(void 0!==b._mapping_dict[c]){if(f=b._mapping_dict[c][0],g=b._mapping_dict[c][1],"equalSubProperty"===f)return d[g]=e[c],g;if("equalValue"===f)return d[c]=g,c;if("ignore"===f||"equalSubId"===f)return!1}if(!b._map_all_property)return!1;if(b._map_all_property)return d[c]=e[c],c;throw new a.util.jIOError("Unsuported option(s): "+b._mapping_dict[c],400)}function m(a,b,c,d){var e,f;if(void 0!==a._mapping_dict[b]){if(e=a._mapping_dict[b][0],f=a._mapping_dict[b][1],"equalSubProperty"===e)return c.hasOwnProperty(f)&&(d[b]=c[f]),f;if("equalValue"===e)return b;if("ignore"===e)return b}return a._map_all_property?(c.hasOwnProperty(b)&&(d[b]=c[b]),b):!1}function n(a,b,c){var d,e={},f=[a._id_mapped];for(d in a._mapping_dict)a._mapping_dict.hasOwnProperty(d)&&f.push(m(a,d,b,e));if(a._map_all_property)for(d in b)b.hasOwnProperty(d)&&f.indexOf(d)<0&&(e[d]=b[d]);return void 0!==a._property_for_sub_id&&void 0!==c&&(e[a._property_for_sub_id]=c),e}function o(a,b,c){var d,e={};for(d in b)b.hasOwnProperty(d)&&l(a,d,e,b);for(d in a._default_mapping)a._default_mapping.hasOwnProperty(d)&&(e[d]=a._default_mapping[d]);return a._id_mapped&&void 0!==c&&(e[a._id_mapped]=c),e}function p(a,b,c){return k(a,b[0]).push(function(d){return b[0]=d,b[1]=j(a,d,b[1],c),a._sub_storage[c+"Attachment"].apply(a._sub_storage,b)})}i.prototype.get=function(a){var b=this;return k(this,a).push(function(a){return b._sub_storage.get(a).push(function(c){return n(b,c,a)})})},i.prototype.post=function(b){var c=o(this,b),d=b[this._property_for_sub_id];if(this._property_for_sub_id&&void 0!==d)return this._sub_storage.put(d,c);if(!this._id_mapped||void 0!==b[this._id_mapped])return this._sub_storage.post(c);throw new a.util.jIOError("post is not supported with id mapped",400)},i.prototype.put=function(b,c){var d=this,e=o(this,c,b);return k(this,b,c).push(function(a){return d._sub_storage.put(a,e)}).push(void 0,function(b){if(b instanceof a.util.jIOError&&404===b.status_code)return d._sub_storage.post(e);throw b}).push(function(){return b})},i.prototype.remove=function(a){var b=this;return k(this,a).push(function(a){return b._sub_storage.remove(a)}).push(function(){return a})},i.prototype.putAttachment=function(a,b){return p(this,arguments,"put",a).push(function(){return b})},i.prototype.getAttachment=function(){return p(this,arguments,"get")},i.prototype.removeAttachment=function(a,b){return p(this,arguments,"remove",a).push(function(){return b})},i.prototype.allAttachments=function(a){var b,c=this;return k(c,a).push(function(a){return b=a,c._sub_storage.allAttachments(b)}).push(function(a){var d,e={},f={};for(d in c._attachment_mapping_dict)c._attachment_mapping_dict.hasOwnProperty(d)&&(f[j(c,b,d,"get")]=d);for(d in a)a.hasOwnProperty(d)&&(f.hasOwnProperty(d)?e[f[d]]={}:e[d]={});return e})},i.prototype.hasCapacity=function(a){return this._sub_storage.hasCapacity(a)},i.prototype.repair=function(){return this._sub_storage.repair.apply(this._sub_storage,arguments)},i.prototype.bulk=function(a){function c(a){return k(d,a.parameter_list[0]).push(function(b){return{method:a.method,parameter_list:[b]}})}var d=this;return(new b.Queue).push(function(){var d=a.map(c);return b.all(d)}).push(function(a){return d._sub_storage.bulk(a)}).push(function(a){var b,c=[];for(b=0;b<a.length;b+=1)c.push(n(d,a[b]));return c})},i.prototype.buildQuery=function(a){function b(a){var c,d,e,f=[];if("complex"===a.type){for(c=0;c<a.query_list.length;c+=1)e=b(a.query_list[c]),e&&f.push(e);return a.query_list=f,a}return d=m(i,a.key,{},{}),
d?(a.key=d,a):!1}var c,d,h,i=this,j=[],k=[];if(void 0!==a.sort_on)for(c=0;c<a.sort_on.length;c+=1)h=m(this,a.sort_on[c][0],{},{}),h&&k.indexOf(h)<0&&k.push([h,a.sort_on[c][1]]);if(void 0!==this._query.sort_on)for(c=0;c<this._query.sort_on.length;c+=1)h=m(this,this._query.sort_on[c],{},{}),k.indexOf(h)<0&&k.push([h,a.sort_on[c][1]]);if(void 0!==a.select_list)for(c=0;c<a.select_list.length;c+=1)h=m(this,a.select_list[c],{},{}),h&&j.indexOf(h)<0&&j.push(h);if(void 0!==this._query.select_list)for(c=0;c<this._query.select_list;c+=1)h=this._query.select_list[c],j.indexOf(h)<0&&j.push(h);return this._id_mapped&&j.push(this._id_mapped),void 0!==a.query&&(d=b(f.create(a.query))),void 0!==this._query.query&&(void 0===d&&(d=this._query.query),d=new e({operator:"AND",query_list:[d,this._query.query],type:"complex"})),void 0!==d&&(d=g.objectToSearchText(d)),this._sub_storage.allDocs({query:d,select_list:j,sort_on:k,limit:a.limit}).push(function(a){var b;for(c=0;c<a.data.total_rows;c+=1)b=a.data.rows[c].value,a.data.rows[c].value=n(i,b),i._id_mapped&&(a.data.rows[c].id=b[i._id_mapped]);return a.data.rows})},a.addStorage("mapping",i)}(jIO,RSVP,UriTemplate,SimpleQuery,ComplexQuery,QueryFactory,Query);
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
/*! jio v3.13.0 2017-03-15 */
function parseStringToObject(a){var b=function(){var a,b,c=[],d=arguments;for(a=0;a<d.length;a+=1)for(b=0;b<d[a].length;b+=1)c.push(d[a][b]);return c},c=function(a,b,c){var d={type:"simple",key:a,value:b};return void 0!==c&&(d.operator=c),d},d=function(a){return"NOT"===a.operator?a.query_list[0]:{type:"complex",operator:"NOT",query_list:[a]}},e=function(a,c){var d,e=[];for(d=0;d<c.length;d+=1)c[d].operator===a?e=b(e,c[d].query_list):e.push(c[d]);return{type:"complex",operator:a,query_list:e}},f=function(a,b){var c;if("complex"===a.type){for(c=0;c<a.query_list.length;++c)f(a.query_list[c],b);return!0}return"simple"!==a.type||a.key?!1:(a.key=b,!0)},g=function(){function a(){this.yy={}}var b=function(a,b,c,d){for(c=c||{},d=a.length;d--;c[a[d]]=b);return c},g=[1,5],h=[1,7],i=[1,8],j=[1,10],k=[1,12],l=[1,6,7,15],m=[1,6,7,9,12,14,15,16,19,21],n=[1,6,7,9,11,12,14,15,16,19,21],o=[2,17],p={trace:function(){},yy:{},symbols_:{error:2,begin:3,search_text:4,end:5,EOF:6,NEWLINE:7,and_expression:8,OR:9,boolean_expression:10,AND:11,NOT:12,expression:13,LEFT_PARENTHESE:14,RIGHT_PARENTHESE:15,WORD:16,DEFINITION:17,value:18,OPERATOR:19,string:20,QUOTE:21,QUOTED_STRING:22,$accept:0,$end:1},terminals_:{2:"error",6:"EOF",7:"NEWLINE",9:"OR",11:"AND",12:"NOT",14:"LEFT_PARENTHESE",15:"RIGHT_PARENTHESE",16:"WORD",17:"DEFINITION",19:"OPERATOR",21:"QUOTE",22:"QUOTED_STRING"},productions_:[0,[3,2],[5,0],[5,1],[5,1],[4,1],[4,2],[4,3],[8,1],[8,3],[10,2],[10,1],[13,3],[13,3],[13,1],[18,2],[18,1],[20,1],[20,3]],performAction:function(a,b,g,h,i,j,k){var l=j.length-1;switch(i){case 1:return j[l-1];case 5:case 8:case 11:case 14:case 16:this.$=j[l];break;case 6:this.$=e("OR",[j[l-1],j[l]]);break;case 7:this.$=e("OR",[j[l-2],j[l]]);break;case 9:this.$=e("AND",[j[l-2],j[l]]);break;case 10:this.$=d(j[l]);break;case 12:this.$=j[l-1];break;case 13:f(j[l],j[l-2]),this.$=j[l];break;case 15:j[l].operator=j[l-1],this.$=j[l];break;case 17:this.$=c("",j[l]);break;case 18:this.$=c("",j[l-1])}},table:[{3:1,4:2,8:3,10:4,12:g,13:6,14:h,16:i,18:9,19:j,20:11,21:k},{1:[3]},{1:[2,2],5:13,6:[1,14],7:[1,15]},b(l,[2,5],{8:3,10:4,13:6,18:9,20:11,4:16,9:[1,17],12:g,14:h,16:i,19:j,21:k}),b(m,[2,8],{11:[1,18]}),{13:19,14:h,16:i,18:9,19:j,20:11,21:k},b(n,[2,11]),{4:20,8:3,10:4,12:g,13:6,14:h,16:i,18:9,19:j,20:11,21:k},b(n,o,{17:[1,21]}),b(n,[2,14]),{16:[1,23],20:22,21:k},b(n,[2,16]),{22:[1,24]},{1:[2,1]},{1:[2,3]},{1:[2,4]},b(l,[2,6]),{4:25,8:3,10:4,12:g,13:6,14:h,16:i,18:9,19:j,20:11,21:k},{8:26,10:4,12:g,13:6,14:h,16:i,18:9,19:j,20:11,21:k},b(n,[2,10]),{15:[1,27]},{13:28,14:h,16:i,18:9,19:j,20:11,21:k},b(n,[2,15]),b(n,o),{21:[1,29]},b(l,[2,7]),b(m,[2,9]),b(n,[2,12]),b(n,[2,13]),b(n,[2,18])],defaultActions:{13:[2,1],14:[2,3],15:[2,4]},parseError:function(a,b){function c(a,b){this.message=a,this.hash=b}if(!b.recoverable)throw c.prototype=new Error,new c(a,b);this.trace(a)},parse:function(a){var b=this,c=[0],d=[null],e=[],f=this.table,g="",h=0,i=0,j=0,k=2,l=1,m=e.slice.call(arguments,1),n=Object.create(this.lexer),o={yy:{}};for(var p in this.yy)Object.prototype.hasOwnProperty.call(this.yy,p)&&(o.yy[p]=this.yy[p]);n.setInput(a,o.yy),o.yy.lexer=n,o.yy.parser=this,"undefined"==typeof n.yylloc&&(n.yylloc={});var q=n.yylloc;e.push(q);var r=n.options&&n.options.ranges;"function"==typeof o.yy.parseError?this.parseError=o.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;for(var s,t,u,v,w,x,y,z,A,B=function(){var a;return a=n.lex()||l,"number"!=typeof a&&(a=b.symbols_[a]||a),a},C={};;){if(u=c[c.length-1],this.defaultActions[u]?v=this.defaultActions[u]:((null===s||"undefined"==typeof s)&&(s=B()),v=f[u]&&f[u][s]),"undefined"==typeof v||!v.length||!v[0]){var D="";A=[];for(x in f[u])this.terminals_[x]&&x>k&&A.push("'"+this.terminals_[x]+"'");D=n.showPosition?"Parse error on line "+(h+1)+":\n"+n.showPosition()+"\nExpecting "+A.join(", ")+", got '"+(this.terminals_[s]||s)+"'":"Parse error on line "+(h+1)+": Unexpected "+(s==l?"end of input":"'"+(this.terminals_[s]||s)+"'"),this.parseError(D,{text:n.match,token:this.terminals_[s]||s,line:n.yylineno,loc:q,expected:A})}if(v[0]instanceof Array&&v.length>1)throw new Error("Parse Error: multiple actions possible at state: "+u+", token: "+s);switch(v[0]){case 1:c.push(s),d.push(n.yytext),e.push(n.yylloc),c.push(v[1]),s=null,t?(s=t,t=null):(i=n.yyleng,g=n.yytext,h=n.yylineno,q=n.yylloc,j>0&&j--);break;case 2:if(y=this.productions_[v[1]][1],C.$=d[d.length-y],C._$={first_line:e[e.length-(y||1)].first_line,last_line:e[e.length-1].last_line,first_column:e[e.length-(y||1)].first_column,last_column:e[e.length-1].last_column},r&&(C._$.range=[e[e.length-(y||1)].range[0],e[e.length-1].range[1]]),w=this.performAction.apply(C,[g,i,h,o.yy,v[1],d,e].concat(m)),"undefined"!=typeof w)return w;y&&(c=c.slice(0,-1*y*2),d=d.slice(0,-1*y),e=e.slice(0,-1*y)),c.push(this.productions_[v[1]][0]),d.push(C.$),e.push(C._$),z=f[c[c.length-2]][c[c.length-1]],c.push(z);break;case 3:return!0}}return!0}},q=function(){var a={EOF:1,parseError:function(a,b){if(!this.yy.parser)throw new Error(a);this.yy.parser.parseError(a,b)},setInput:function(a,b){return this.yy=b||this.yy||{},this._input=a,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var a=this._input[0];this.yytext+=a,this.yyleng++,this.offset++,this.match+=a,this.matched+=a;var b=a.match(/(?:\r\n?|\n).*/g);return b?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),a},unput:function(a){var b=a.length,c=a.split(/(?:\r\n?|\n)/g);this._input=a+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-b),this.offset-=b;var d=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),c.length-1&&(this.yylineno-=c.length-1);var e=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:c?(c.length===d.length?this.yylloc.first_column:0)+d[d.length-c.length].length-c[0].length:this.yylloc.first_column-b},this.options.ranges&&(this.yylloc.range=[e[0],e[0]+this.yyleng-b]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){return this.options.backtrack_lexer?(this._backtrack=!0,this):this.parseError("Lexical error on line "+(this.yylineno+1)+". You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},less:function(a){this.unput(this.match.slice(a))},pastInput:function(){var a=this.matched.substr(0,this.matched.length-this.match.length);return(a.length>20?"...":"")+a.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var a=this.match;return a.length<20&&(a+=this._input.substr(0,20-a.length)),(a.substr(0,20)+(a.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var a=this.pastInput(),b=new Array(a.length+1).join("-");return a+this.upcomingInput()+"\n"+b+"^"},test_match:function(a,b){var c,d,e;if(this.options.backtrack_lexer&&(e={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(e.yylloc.range=this.yylloc.range.slice(0))),d=a[0].match(/(?:\r\n?|\n).*/g),d&&(this.yylineno+=d.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:d?d[d.length-1].length-d[d.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+a[0].length},this.yytext+=a[0],this.match+=a[0],this.matches=a,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(a[0].length),this.matched+=a[0],c=this.performAction.call(this,this.yy,this,b,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),c)return c;if(this._backtrack){for(var f in e)this[f]=e[f];return!1}return!1},next:function(){if(this.done)return this.EOF;this._input||(this.done=!0);var a,b,c,d;this._more||(this.yytext="",this.match="");for(var e=this._currentRules(),f=0;f<e.length;f++)if(c=this._input.match(this.rules[e[f]]),c&&(!b||c[0].length>b[0].length)){if(b=c,d=f,this.options.backtrack_lexer){if(a=this.test_match(c,e[f]),a!==!1)return a;if(this._backtrack){b=!1;continue}return!1}if(!this.options.flex)break}return b?(a=this.test_match(b,e[d]),a!==!1?a:!1):""===this._input?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+". Unrecognized text.\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){var a=this.next();return a?a:this.lex()},begin:function(a){this.conditionStack.push(a)},popState:function(){var a=this.conditionStack.length-1;return a>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(a){return a=this.conditionStack.length-1-Math.abs(a||0),a>=0?this.conditionStack[a]:"INITIAL"},pushState:function(a){this.begin(a)},stateStackSize:function(){return this.conditionStack.length},options:{},performAction:function(a,b,c,d){switch(c){case 0:return this.begin("letsquote"),"QUOTE";case 1:return this.popState(),this.begin("endquote"),"QUOTED_STRING";case 2:return this.popState(),"QUOTE";case 3:break;case 4:return"LEFT_PARENTHESE";case 5:return"RIGHT_PARENTHESE";case 6:return"AND";case 7:return"OR";case 8:return"NOT";case 9:return"DEFINITION";case 10:return 19;case 11:return 16;case 12:return 6}},rules:[/^(?:")/,/^(?:(\\"|[^"])*)/,/^(?:")/,/^(?:[^\S]+)/,/^(?:\()/,/^(?:\))/,/^(?:AND\b)/,/^(?:OR\b)/,/^(?:NOT\b)/,/^(?::)/,/^(?:(!?=|<=?|>=?))/,/^(?:[^\s\n"():><!=]+)/,/^(?:$)/],conditions:{endquote:{rules:[2],inclusive:!1},letsquote:{rules:[1],inclusive:!1},INITIAL:{rules:[0,3,4,5,6,7,8,9,10,11,12],inclusive:!0}}};return a}();return p.lexer=q,a.prototype=p,p.Parser=a,new a}();return g.parse(a)}!function(a,b,c){"use strict";function d(a){var b,c=[];if(void 0===a)return void 0;for(Array.isArray(a)||(a=[a]),b=0;b<a.length;b+=1)"object"==typeof a[b]?c[b]=a[b].content:c[b]=a[b];return c}function e(a,b){var c;if("descending"===b)c=1;else{if("ascending"!==b)throw new TypeError("Query.sortFunction(): Argument 2 must be 'ascending' or 'descending'");c=-1}return function(b,e){var f,g;for(b=d(b[a])||[],e=d(e[a])||[],g=b.length>e.length?b.length:e.length,f=0;g>f;f+=1){if(void 0===b[f])return c;if(void 0===e[f])return-c;if(b[f]>e[f])return-c;if(b[f]<e[f])return c}return 0}}function f(a,b){var c;if(!Array.isArray(a))throw new TypeError("jioquery.sortOn(): Argument 1 is not of type 'array'");for(c=a.length-1;c>=0;c-=1)b.sort(e(a[c][0],a[c][1]));return b}function g(a,b){if(!Array.isArray(a))throw new TypeError("jioquery.limit(): Argument 1 is not of type 'array'");if(!Array.isArray(b))throw new TypeError("jioquery.limit(): Argument 2 is not of type 'array'");return b.splice(0,a[0]),a[1]&&b.splice(a[1]),b}function h(a,b){var c,d,e;if(!Array.isArray(a))throw new TypeError("jioquery.select(): Argument 1 is not of type Array");if(!Array.isArray(b))throw new TypeError("jioquery.select(): Argument 2 is not of type Array");for(c=0;c<b.length;c+=1){for(e={},d=0;d<a.length;d+=1)b[c].hasOwnProperty([a[d]])&&(e[a[d]]=b[c][a[d]]);for(d in e)if(e.hasOwnProperty(d)){b[c]=e;break}}return b}function i(){}function j(){}function k(a){return a.replace(t,"\\$&")}function l(a,b){a.super_=b,a.prototype=Object.create(b.prototype,{constructor:{configurable:!0,enumerable:!1,writable:!0,value:a}})}function m(a,b){if("string"!=typeof a)throw new TypeError("jioquery.searchTextToRegExp(): Argument 1 is not of type 'string'");return b===!1?new RegExp("^"+k(a)+"$"):new RegExp("^"+k(a).replace(u,".*").replace(v,".")+"$")}function n(a,b){i.call(this),this.operator=a.operator,this.query_list=a.query_list||[],this.query_list=this.query_list.map(function(a){return j.create(a,b)})}function o(a){var b=[];if("complex"===a.type)return b.push("("),(a.query_list||[]).forEach(function(c){b.push(o(c)),b.push(a.operator)}),b.length-=1,b.push(")"),b.join(" ");if("simple"===a.type)return(a.key?a.key+": ":"")+(a.operator||"")+' "'+a.value+'"';throw new TypeError("This object is not a query")}function p(a){var b;if(void 0!==a){if("object"!=typeof a)throw new TypeError("SimpleQuery().create(): key_schema is not of type 'object'");if(void 0===a.key_set)throw new TypeError("SimpleQuery().create(): key_schema has no 'key_set' property");for(b in a)if(a.hasOwnProperty(b))switch(b){case"key_set":case"cast_lookup":case"match_lookup":break;default:throw new TypeError("SimpleQuery().create(): key_schema has unknown property '"+b+"'")}}}function q(a,b){i.call(this),p(b),this._key_schema=b||{},this.operator=a.operator,this.key=a.key,this.value=a.value}function r(a){var b;if(void 0===a.read_from)throw new TypeError("Custom key is missing the read_from property");for(b in a)if(a.hasOwnProperty(b))switch(b){case"read_from":case"cast_to":case"equal_match":break;default:throw new TypeError("Custom key has unknown property '"+b+"'")}}var s={},t=/[\-\[\]{}()*+?.,\\\^$|#\s]/g,u=/%/g,v=/_/g,w=/^(?:AND|OR|NOT)$/i,x=/^(?:!?=|<=?|>=?)$/i;i.prototype.exec=function(b,c){if(!Array.isArray(b))throw new TypeError("Query().exec(): Argument 1 is not of type 'array'");if(void 0===c&&(c={}),"object"!=typeof c)throw new TypeError("Query().exec(): Optional argument 2 is not of type 'object'");var d,e=this;for(d=b.length-1;d>=0;d-=1)e.match(b[d])||b.splice(d,1);return c.sort_on&&f(c.sort_on,b),c.limit&&g(c.limit,b),h(c.select_list||[],b),(new a.Queue).push(function(){return b})},i.prototype.match=function(){return!0},i.prototype.parse=function(b){function c(b,d){function f(a){i.push(function(){return b.parsed=h.query_list[a],c(b,d)}).push(function(){h.query_list[a]=b.parsed})}var g,h=b.parsed,i=new a.Queue;if("complex"===h.type){for(g=0;g<h.query_list.length;g+=1)f(g);return i.push(function(){return b.parsed=h,e.onParseComplexQuery(b,d)})}return"simple"===h.type?e.onParseSimpleQuery(b,d):void 0}var d,e=this;return d={parsed:JSON.parse(JSON.stringify(e.serialized()))},(new a.Queue).push(function(){return e.onParseStart(d,b)}).push(function(){return c(d,b)}).push(function(){return e.onParseEnd(d,b)}).push(function(){return d.parsed})},i.prototype.toString=function(){return""},i.prototype.serialized=function(){return void 0},l(n,i),n.prototype.operator="AND",n.prototype.type="complex",n.prototype.match=function(a){var b=this.operator;return w.test(b)||(b="AND"),this[b.toUpperCase()](a)},n.prototype.toString=function(){var a=[],b=this.operator;return"NOT"===this.operator?(a.push("NOT ("),a.push(this.query_list[0].toString()),a.push(")"),a.join(" ")):(this.query_list.forEach(function(c){a.push("("),a.push(c.toString()),a.push(")"),a.push(b)}),a.length-=1,a.join(" "))},n.prototype.serialized=function(){var a={type:"complex",operator:this.operator,query_list:[]};return this.query_list.forEach(function(b){a.query_list.push("function"==typeof b.toJSON?b.toJSON():b)}),a},n.prototype.toJSON=n.prototype.serialized,n.prototype.AND=function(a){for(var b=!0,c=0;b&&c!==this.query_list.length;)b=this.query_list[c].match(a),c+=1;return b},n.prototype.OR=function(a){for(var b=!1,c=0;!b&&c!==this.query_list.length;)b=this.query_list[c].match(a),c+=1;return b},n.prototype.NOT=function(a){return!this.query_list[0].match(a)},j.create=function(a,b){if(""===a)return new i;if("string"==typeof a&&(a=c(a)),"string"==typeof(a||{}).type&&s[a.type])return new s[a.type](a,b);throw new TypeError("QueryFactory.create(): Argument 1 is not a search text or a parsable object")},l(q,i),q.prototype.type="simple",q.prototype.match=function(a){var b=null,c=null,d=null,e=null,f=this.operator,g=null,h=this.key;if(x.test(f)||(f=u.test(this.value)?"like":"="),e=this[f],this._key_schema.key_set&&void 0!==this._key_schema.key_set[h]&&(h=this._key_schema.key_set[h]),"object"==typeof h){if(r(h),b=a[h.read_from],c=h.equal_match,"string"==typeof c&&(c=this._key_schema.match_lookup[c]),void 0!==c&&(e="="===f||"like"===f?c:e),g=this.value,d=h.cast_to){"string"==typeof d&&(d=this._key_schema.cast_lookup[d]);try{g=d(g)}catch(i){g=void 0}try{b=d(b)}catch(i){b=void 0}}}else b=a[h],g=this.value;return void 0===b||void 0===g?!1:e(b,g)},q.prototype.toString=function(){return(this.key?this.key+":":"")+(this.operator?" "+this.operator:"")+' "'+this.value+'"'},q.prototype.serialized=function(){var a={type:"simple",key:this.key,value:this.value};return void 0!==this.operator&&(a.operator=this.operator),a},q.prototype.toJSON=q.prototype.serialized,q.prototype["="]=function(a,b){var c,d;for(Array.isArray(a)||(a=[a]),d=0;d<a.length;d+=1){if(c=a[d],"object"==typeof c&&c.hasOwnProperty("content")&&(c=c.content),"function"==typeof c.cmp)return 0===c.cmp(b);if(b.toString()===c.toString())return!0}return!1},q.prototype.like=function(a,b){var c,d;for(Array.isArray(a)||(a=[a]),d=0;d<a.length;d+=1){if(c=a[d],"object"==typeof c&&c.hasOwnProperty("content")&&(c=c.content),"function"==typeof c.cmp)return 0===c.cmp(b);if(m(b.toString()).test(c.toString()))return!0}return!1},q.prototype["!="]=function(a,b){var c,d;for(Array.isArray(a)||(a=[a]),d=0;d<a.length;d+=1){if(c=a[d],"object"==typeof c&&c.hasOwnProperty("content")&&(c=c.content),"function"==typeof c.cmp)return 0!==c.cmp(b);if(b.toString()===c.toString())return!1}return!0},q.prototype["<"]=function(a,b){var c;return Array.isArray(a)||(a=[a]),c=a[0],"object"==typeof c&&c.hasOwnProperty("content")&&(c=c.content),"function"==typeof c.cmp?c.cmp(b)<0:b>c},q.prototype["<="]=function(a,b){var c;return Array.isArray(a)||(a=[a]),c=a[0],"object"==typeof c&&c.hasOwnProperty("content")&&(c=c.content),"function"==typeof c.cmp?c.cmp(b)<=0:b>=c},q.prototype[">"]=function(a,b){var c;return Array.isArray(a)||(a=[a]),c=a[0],"object"==typeof c&&c.hasOwnProperty("content")&&(c=c.content),"function"==typeof c.cmp?c.cmp(b)>0:c>b},q.prototype[">="]=function(a,b){var c;return Array.isArray(a)||(a=[a]),c=a[0],"object"==typeof c&&c.hasOwnProperty("content")&&(c=c.content),"function"==typeof c.cmp?c.cmp(b)>=0:c>=b},s.simple=q,s.complex=n,i.parseStringToObject=c,i.objectToSearchText=o,b.Query=i,b.SimpleQuery=q,b.ComplexQuery=n,b.QueryFactory=j}(RSVP,window,parseStringToObject),function(a,b){"use strict";var c,d="year",e="month",f="day",g="hour",h="minute",i="second",j="millisecond",k={year:0,month:1,day:2,hour:3,minute:4,second:5,millisecond:6},l=function(a,b){return k[a]<k[b]?a:b};c=function(a){if(!(this instanceof c))return new c(a);if(a instanceof c)return this.mom=a.mom.clone(),void(this._precision=a._precision);if(void 0===a)return this.mom=b(),void this.setPrecision(j);if(this.mom=null,this._str=a,a.match(/\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+\-][0-2]\d:[0-5]\d|Z)/)||a.match(/\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d\.\d\d\d/)?(this.mom=b(a),this.setPrecision(j)):a.match(/\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+\-][0-2]\d:[0-5]\d|Z)/)||a.match(/\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d/)?(this.mom=b(a),this.setPrecision(i)):a.match(/\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+\-][0-2]\d:[0-5]\d|Z)/)||a.match(/\d\d\d\d-\d\d-\d\d \d\d:\d\d/)?(this.mom=b(a),this.setPrecision(h)):a.match(/\d\d\d\d-\d\d-\d\d \d\d/)?(this.mom=b(a),this.setPrecision(g)):a.match(/\d\d\d\d-\d\d-\d\d/)?(this.mom=b(a),this.setPrecision(f)):a.match(/\d\d\d\d-\d\d/)?(this.mom=b(a),this.setPrecision(e)):a.match(/\d\d\d\d/)&&(this.mom=b(a,"YYYY"),this.setPrecision(d)),!this.mom)throw new Error("Cannot parse: "+a)},c.prototype.setPrecision=function(a){this._precision=a},c.prototype.getPrecision=function(){return this._precision},c.prototype.cmp=function(a){var b=this.mom,c=a.mom,d=l(this._precision,a._precision);return b.isBefore(c,d)?-1:b.isSame(c,d)?0:1},c.prototype.toPrecisionString=function(a){var b;if(a=a||this._precision,b={millisecond:"YYYY-MM-DD HH:mm:ss.SSS",second:"YYYY-MM-DD HH:mm:ss",minute:"YYYY-MM-DD HH:mm",hour:"YYYY-MM-DD HH",day:"YYYY-MM-DD",month:"YYYY-MM",year:"YYYY"}[a],!b)throw new TypeError("Unsupported precision value '"+a+"'");return this.mom.format(b)},c.prototype.toString=function(){return this._str},a.jiodate={JIODate:c,YEAR:d,MONTH:e,DAY:f,HOUR:g,MIN:h,SEC:i,MSEC:j}}(window,moment),function(a,b,c,d,e,f,g,h,i,j){"use strict";function k(a,b){if(void 0!==a&&"string"!=typeof a)throw new TypeError("You must pass a string.");this.message=a||"Default Message",this.status_code=b||500}function l(a){var c=new XMLHttpRequest;return new b.Promise(function(b,d,e){var f,g=new StreamBuffers.WritableStreamBuffer;if(c.open(a.type||"GET",a.url,!0),c.responseType=a.dataType||"","object"==typeof a.headers&&null!==a.headers)for(f in a.headers)a.headers.hasOwnProperty(f)&&c.setRequestHeader(f,a.headers[f]);if(c.setRequestHeader("Accept","*/*"),c.addEventListener("load",function(a){return a.target.status>=400?d(a):void b(a)}),c.addEventListener("error",d),c.addEventListener("progress",e),"object"==typeof a.xhrFields&&null!==a.xhrFields)for(f in a.xhrFields)a.xhrFields.hasOwnProperty(f)&&(c[f]=a.xhrFields[f]);"function"==typeof a.beforeSend&&a.beforeSend(c),a.data instanceof FormData?(c.setRequestHeader("Content-Type","multipart/form-data; boundary="+a.data.getBoundary()),a.data.pipe(g),c.send(g.getContents())):c.send(a.data)},function(){c.abort()})}function m(a,c){var d=new g;return new b.Promise(function(b,e,f){d.addEventListener("load",b),d.addEventListener("error",e),d.addEventListener("progress",f),d.readAsText(a,c)},function(){d.abort()})}function n(a){var c=new g;return new b.Promise(function(b,d,e){c.addEventListener("load",b),c.addEventListener("error",d),c.addEventListener("progress",e),c.readAsArrayBuffer(a)},function(){c.abort()})}function o(a){var c=new g;return new b.Promise(function(b,d,e){c.addEventListener("load",b),c.addEventListener("error",d),c.addEventListener("progress",e),c.readAsDataURL(a)},function(){c.abort()})}function p(a){var b,c,d,e,f;if(void 0===a)return void 0;if(a.constructor===Object){for(c=Object.keys(a).sort(),f=[],d=0;d<c.length;d+=1)b=c[d],e=p(a[b]),void 0!==e&&f.push(p(b)+":"+e);return"{"+f.join(",")+"}"}if(a.constructor===Array){for(f=[],d=0;d<a.length;d+=1)f.push(p(a[d]));return"["+f.join(",")+"]"}return JSON.stringify(a)}function q(a){if("data:"===a)return new c;var b,d=f(a.split(",")[1]),e=a.split(",")[0].split(":")[1],g=new h(d.length),j=new i(g);for(e=e.slice(0,e.length-";base64".length),b=0;b<d.length;b+=1)j[b]=d.charCodeAt(b);return new c([g],{type:e})}function r(a,b,c){if("string"!=typeof a[0]||""===a[0])throw new w.util.jIOError("Document id must be a non empty string on '"+b.__type+"."+c+"'.",400)}function s(a,b,c){if("string"!=typeof a[1]||""===a[1])throw new w.util.jIOError("Attachment id must be a non empty string on '"+b.__type+"."+c+"'.",400)}function t(a,c,d,e){return a.prototype[c]=function(){var a,f=arguments,g=this;return(new b.Queue).push(function(){return void 0!==d?d.apply(g.__storage,[f,g,c]):void 0}).push(function(b){var d=g.__storage[c];if(a=b,void 0===d)throw new w.util.jIOError("Capacity '"+c+"' is not implemented on '"+g.__type+"'",501);return d.apply(g.__storage,f)}).push(function(b){return void 0!==e?e.call(g,f,b,a):b})},this}function u(a,b){return this instanceof u?(this.__type=a,void(this.__storage=b)):new u}function v(){return this instanceof v?void(this.__storage_types={}):new v}void 0===a.openDatabase&&(a.openDatabase=function(){throw new Error("WebSQL is not supported by "+j.userAgent)});var w,x={};k.prototype=new Error,k.prototype.constructor=k,x.jIOError=k,x.ajax=l,x.readBlobAsText=m,x.readBlobAsArrayBuffer=n,x.readBlobAsDataURL=o,x.stringify=p,x.dataURItoBlob=q,t(u,"put",r,function(a){return a[0]}),t(u,"get",r),t(u,"bulk"),t(u,"remove",r,function(a){return a[0]}),u.prototype.post=function(){var a=this,c=arguments;return(new b.Queue).push(function(){var b=a.__storage.post;if(void 0===b)throw new w.util.jIOError("Capacity 'post' is not implemented on '"+a.__type+"'",501);return a.__storage.post.apply(a.__storage,c)})},t(u,"putAttachment",function(a,b,d){r(a,b,d),s(a,b,d);var e=a[3]||{};if("string"==typeof a[2])a[2]=new c([a[2]],{type:e._content_type||e._mimetype||"text/plain;charset=utf-8"});else if(!(a[2]instanceof c))throw new w.util.jIOError("Attachment content is not a blob",400)}),t(u,"removeAttachment",function(a,b,c){r(a,b,c),s(a,b,c)}),t(u,"getAttachment",function(a,b,c){var d="blob";return r(a,b,c),s(a,b,c),void 0!==a[2]&&(d=a[2].format||d,delete a[2].format),d},function(a,d,e){var f;if(!(d instanceof c))throw new w.util.jIOError("'getAttachment' ("+a[0]+" , "+a[1]+") on '"+this.__type+"' does not return a Blob.",501);if("blob"===e)f=d;else if("data_url"===e)f=(new b.Queue).push(function(){return w.util.readBlobAsDataURL(d)}).push(function(a){return a.target.result});else if("array_buffer"===e)f=(new b.Queue).push(function(){return w.util.readBlobAsArrayBuffer(d)}).push(function(a){return a.target.result});else if("text"===e)f=(new b.Queue).push(function(){return w.util.readBlobAsText(d)}).push(function(a){return a.target.result});else{if("json"!==e)throw new w.util.jIOError(this.__type+".getAttachment format: '"+e+"' is not supported",400);f=(new b.Queue).push(function(){return w.util.readBlobAsText(d)}).push(function(a){return JSON.parse(a.target.result)})}return f}),u.prototype.buildQuery=function(){var a=this.__storage.buildQuery,c=this,d=arguments;if(void 0===a)throw new w.util.jIOError("Capacity 'buildQuery' is not implemented on '"+this.__type+"'",501);return(new b.Queue).push(function(){return a.apply(c.__storage,d)})},u.prototype.hasCapacity=function(a){var b=this.__storage.hasCapacity,c=this.__storage[a];if(void 0!==c)return!0;if(void 0===b||!b.apply(this.__storage,arguments))throw new w.util.jIOError("Capacity '"+a+"' is not implemented on '"+this.__type+"'",501);return!0},u.prototype.allDocs=function(a){var c=this;return void 0===a&&(a={}),(new b.Queue).push(function(){return!c.hasCapacity("list")||void 0!==a.query&&!c.hasCapacity("query")||void 0!==a.sort_on&&!c.hasCapacity("sort")||void 0!==a.select_list&&!c.hasCapacity("select")||void 0!==a.include_docs&&!c.hasCapacity("include")||void 0!==a.limit&&!c.hasCapacity("limit")?void 0:c.buildQuery(a)}).push(function(a){return{data:{rows:a,total_rows:a.length}}})},t(u,"allAttachments",r),t(u,"repair"),u.prototype.repair=function(){var a=this,c=arguments;return(new b.Queue).push(function(){var b=a.__storage.repair;return void 0!==b?a.__storage.repair.apply(a.__storage,c):void 0})},v.prototype.createJIO=function(a,b){if("string"!=typeof a.type)throw new TypeError("Invalid storage description");if(!this.__storage_types[a.type])throw new TypeError("Unknown storage '"+a.type+"'");return new u(a.type,new this.__storage_types[a.type](a,b))},v.prototype.addStorage=function(a,b){if("string"!=typeof a)throw new TypeError("jIO.addStorage(): Argument 1 is not of type 'string'");if("function"!=typeof b)throw new TypeError("jIO.addStorage(): Argument 2 is not of type 'function'");if(void 0!==this.__storage_types[a])throw new TypeError("jIO.addStorage(): Storage type already exists");this.__storage_types[a]=b},v.prototype.util=x,v.prototype.QueryFactory=d,v.prototype.Query=e,w=new v,a.jIO=w}(window,RSVP,Blob,QueryFactory,Query,atob,FileReader,ArrayBuffer,Uint8Array,navigator),function(a,b,c,d){"use strict";function e(a){return h.digestFromString(a)}function f(a){return h.digestFromArrayBuffer(a)}function g(b){if(this._query_options=b.query||{},this._local_sub_storage=a.createJIO(b.local_sub_storage),this._remote_sub_storage=a.createJIO(b.remote_sub_storage),this._signature_hash="_replicate_"+e(d(b.local_sub_storage)+d(b.remote_sub_storage)+d(this._query_options)),this._signature_sub_storage=a.createJIO({type:"document",document_id:this._signature_hash,sub_storage:b.signature_storage||b.local_sub_storage}),this._use_remote_post=b.use_remote_post||!1,this._conflict_handling=b.conflict_handling||0,this._conflict_handling!==i&&this._conflict_handling!==j&&this._conflict_handling!==k&&this._conflict_handling!==l)throw new a.util.jIOError("Unsupported conflict handling: "+this._conflict_handling,400);this._check_local_modification=b.check_local_modification,void 0===this._check_local_modification&&(this._check_local_modification=!0),this._check_local_creation=b.check_local_creation,void 0===this._check_local_creation&&(this._check_local_creation=!0),this._check_local_deletion=b.check_local_deletion,void 0===this._check_local_deletion&&(this._check_local_deletion=!0),this._check_remote_modification=b.check_remote_modification,void 0===this._check_remote_modification&&(this._check_remote_modification=!0),this._check_remote_creation=b.check_remote_creation,void 0===this._check_remote_creation&&(this._check_remote_creation=!0),this._check_remote_deletion=b.check_remote_deletion,void 0===this._check_remote_deletion&&(this._check_remote_deletion=!0),this._check_local_attachment_modification=b.check_local_attachment_modification,void 0===this._check_local_attachment_modification&&(this._check_local_attachment_modification=!1),this._check_local_attachment_creation=b.check_local_attachment_creation,void 0===this._check_local_attachment_creation&&(this._check_local_attachment_creation=!1),this._check_local_attachment_deletion=b.check_local_attachment_deletion,void 0===this._check_local_attachment_deletion&&(this._check_local_attachment_deletion=!1),this._check_remote_attachment_modification=b.check_remote_attachment_modification,void 0===this._check_remote_attachment_modification&&(this._check_remote_attachment_modification=!1),this._check_remote_attachment_creation=b.check_remote_attachment_creation,void 0===this._check_remote_attachment_creation&&(this._check_remote_attachment_creation=!1),this._check_remote_attachment_deletion=b.check_remote_attachment_deletion,void 0===this._check_remote_attachment_deletion&&(this._check_remote_attachment_deletion=!1)}var h=new c,i=0,j=1,k=2,l=3;g.prototype.remove=function(b){if(b===this._signature_hash)throw new a.util.jIOError(this._signature_hash+" is frozen",403);return this._local_sub_storage.remove.apply(this._local_sub_storage,arguments)},g.prototype.post=function(){return this._local_sub_storage.post.apply(this._local_sub_storage,arguments)},g.prototype.put=function(b){if(b===this._signature_hash)throw new a.util.jIOError(this._signature_hash+" is frozen",403);return this._local_sub_storage.put.apply(this._local_sub_storage,arguments)},g.prototype.get=function(){return this._local_sub_storage.get.apply(this._local_sub_storage,arguments)},g.prototype.getAttachment=function(){return this._local_sub_storage.getAttachment.apply(this._local_sub_storage,arguments)},g.prototype.allAttachments=function(){return this._local_sub_storage.allAttachments.apply(this._local_sub_storage,arguments)},g.prototype.putAttachment=function(b){if(b===this._signature_hash)throw new a.util.jIOError(this._signature_hash+" is frozen",403);return this._local_sub_storage.putAttachment.apply(this._local_sub_storage,arguments)},g.prototype.removeAttachment=function(b){if(b===this._signature_hash)throw new a.util.jIOError(this._signature_hash+" is frozen",403);return this._local_sub_storage.removeAttachment.apply(this._local_sub_storage,arguments)},g.prototype.hasCapacity=function(){return this._local_sub_storage.hasCapacity.apply(this._local_sub_storage,arguments);
},g.prototype.buildQuery=function(){return this._local_sub_storage.buildQuery.apply(this._local_sub_storage,arguments)},g.prototype.repair=function(){function c(a,b,c,d){return b.removeAttachment(c,d).push(function(){return w._signature_sub_storage.removeAttachment(c,d)}).push(function(){a[d]=null})}function g(a,b,c,d,e,f){return b.putAttachment(e,f,c).push(function(){return w._signature_sub_storage.putAttachment(e,f,JSON.stringify({hash:d}))}).push(function(){a[f]=null})}function h(b,d,e,h,i,j,k,l,m,n,o){var p;return j.getAttachment(k,l).push(function(b){return p=b,a.util.readBlobAsArrayBuffer(p)}).push(function(a){return f(a.target.result)},function(b){if(b instanceof a.util.jIOError&&404===b.status_code)return p=null,null;throw b}).push(function(f){if(e===f)return null===e?w._signature_sub_storage.removeAttachment(k,l).push(function(){b[k]=null}):w._signature_sub_storage.putAttachment(k,l,JSON.stringify({hash:e})).push(function(){y[k]=null});if(f===d||m===!0)return null===e?c(b,j,k,l):g(b,j,h,e,k,l);if(o!==!0){if(n===!0||null===e)return null===f?c(b,i,k,l):g(b,i,p,f,k,l);if(null===f)return g(b,j,h,e,k,l);throw new a.util.jIOError("Conflict on '"+k+"' with attachment '"+l+"'",409)}})}function i(c,d,e,g,i,j,k,l,m,n,o){var p,q;d.push(function(){if(n===!0)return b.all([e.getAttachment(i,j),{hash:null}]);if(o===!0)return b.all([e.getAttachment(i,j),w._signature_sub_storage.getAttachment(i,j,{format:"json"})]);throw new a.util.jIOError("Unexpected call of checkAttachmentSignatureDifference",409)}).push(function(b){return p=b[0],q=b[1].hash,a.util.readBlobAsArrayBuffer(p)}).push(function(a){var b=a.target.result,d=f(b);return d!==q?h(c,q,d,p,e,g,i,j,k,l,m):void 0})}function m(a,b,c,d,e,f,g,i,j){var k;b.push(function(){return w._signature_sub_storage.getAttachment(d,e,{format:"json"})}).push(function(b){return k=b.hash,h(a,k,null,null,f,c,d,e,g,i,j)})}function n(c,d,e,f,g){var h=new b.Queue;return h.push(function(){return b.all([e.allAttachments(d).push(void 0,function(b){if(b instanceof a.util.jIOError&&404===b.status_code)return{};throw b}),w._signature_sub_storage.allAttachments(d).push(void 0,function(b){if(b instanceof a.util.jIOError&&404===b.status_code)return{};throw b})])}).push(function(a){var b,j,k,l={},n={};for(k in a[0])a[0].hasOwnProperty(k)&&(c.hasOwnProperty(k)||(l[k]=null));for(k in a[1])a[1].hasOwnProperty(k)&&(c.hasOwnProperty(k)||(n[k]=null));for(k in l)l.hasOwnProperty(k)&&(b=n.hasOwnProperty(k)&&g.check_modification,j=!n.hasOwnProperty(k)&&g.check_creation,(b===!0||j===!0)&&i(c,h,e,f,d,k,g.conflict_force,g.conflict_revert,g.conflict_ignore,j,b));if(g.check_deletion===!0)for(k in n)n.hasOwnProperty(k)&&(l.hasOwnProperty(k)||m(c,h,f,d,k,e,g.conflict_force,g.conflict_revert,g.conflict_ignore))})}function o(a){var c={};return(new b.Queue).push(function(){return w._check_local_attachment_modification||w._check_local_attachment_creation||w._check_local_attachment_deletion?n(c,a,w._local_sub_storage,w._remote_sub_storage,{conflict_force:w._conflict_handling===j,conflict_revert:w._conflict_handling===k,conflict_ignore:w._conflict_handling===l,check_modification:w._check_local_attachment_modification,check_creation:w._check_local_attachment_creation,check_deletion:w._check_local_attachment_deletion}):void 0}).push(function(){return w._check_remote_attachment_modification||w._check_remote_attachment_creation||w._check_remote_attachment_deletion?n(c,a,w._remote_sub_storage,w._local_sub_storage,{use_revert_post:w._use_remote_post,conflict_force:w._conflict_handling===k,conflict_revert:w._conflict_handling===j,conflict_ignore:w._conflict_handling===l,check_modification:w._check_remote_attachment_modification,check_creation:w._check_remote_attachment_creation,check_deletion:w._check_remote_attachment_deletion}):void 0})}function p(a,c,d,e,f,g){var h,i,j=!0;return void 0===g&&(g={}),h=g.use_post?c.post(d).push(function(b){return j=!1,i=b,a.put(i,d)}).push(function(){return a.allAttachments(f)}).push(function(c){function d(b){g.push(function(){return a.getAttachment(f,b)}).push(function(c){return a.putAttachment(i,b,c)})}var e,g=new b.Queue;for(e in c)c.hasOwnProperty(e)&&d(e);return g}).push(function(){return a.remove(f)}).push(function(){return w._signature_sub_storage.remove(f)}).push(function(){return j=!0,w._signature_sub_storage.put(i,{hash:e})}).push(function(){y[i]=null}):c.put(f,d).push(function(){return w._signature_sub_storage.put(f,{hash:e})}),h.push(function(){j&&(y[f]=null)})}function q(b,c){return o(c).push(function(){return b.allAttachments(c)}).push(function(a){return"{}"===JSON.stringify(a)?b.remove(c).push(function(){return w._signature_sub_storage.remove(c)}):void 0},function(b){if(!(b instanceof a.util.jIOError&&404===b.status_code))throw b}).push(function(){y[c]=null})}function r(b,c,f,g,h,i,j,k,l,m){return h.get(i).push(function(a){return[a,e(d(a))]},function(b){if(b instanceof a.util.jIOError&&404===b.status_code)return[null,null];throw b}).push(function(e){var n=e[0],o=e[1];if(c===o)return null===c?w._signature_sub_storage.remove(i).push(function(){y[i]=null}):w._signature_sub_storage.put(i,{hash:c}).push(function(){y[i]=null});if(o===b||j===!0)return null===c?q(h,i):p(g,h,f,c,i,{use_post:m.use_post&&null===o});if(l!==!0){if(k===!0||null===c)return null===o?q(g,i):p(h,g,n,o,i,{use_post:m.use_revert_post&&null===c});if(null===o)return p(g,h,f,c,i,{use_post:m.use_post});throw new a.util.jIOError("Conflict on '"+i+"': "+d(f||"")+" !== "+d(n||""),409)}})}function s(a,b,c,d,e,f,g,h){var i;a.push(function(){return w._signature_sub_storage.get(c)}).push(function(a){return i=a.hash,r(i,null,null,d,b,c,e,f,g,h)})}function t(c,f,g,h,i,j,k,l,m,n,o){c.push(function(){if(l===!0)return b.all([n(h),{hash:null}]);if(m===!0)return b.all([n(h),w._signature_sub_storage.get(h)]);throw new a.util.jIOError("Unexpected call of checkSignatureDifference",409)}).push(function(a){var b=a[0],c=e(d(b)),l=a[1].hash;return c!==l?r(l,c,b,f,g,h,i,j,k,o):void 0})}function u(a,c,d,e,f,g,h,i,j){a.push(function(){return c.bulk(e)}).push(function(a){function k(b){return function(c){if(c!==e[b].parameter_list[0])throw new Error("Does not access expected ID "+c);return a[b]}}var l,m=new b.Queue;for(l=0;l<a.length;l+=1)t(m,c,d,e[l].parameter_list[0],h,i,j,f[l].is_creation,f[l].is_modification,k(l),g);return m})}function v(a,c,d){var e=new b.Queue;return d.hasOwnProperty("use_post")||(d.use_post=!1),d.hasOwnProperty("use_revert_post")||(d.use_revert_post=!1),e.push(function(){return b.all([a.allDocs(w._query_options),w._signature_sub_storage.allDocs()])}).push(function(b){var f,g,h,i,j={},k=[],l=[],m={};for(f=0;f<b[0].data.total_rows;f+=1)y.hasOwnProperty(b[0].data.rows[f].id)||(j[b[0].data.rows[f].id]=f);for(f=0;f<b[1].data.total_rows;f+=1)y.hasOwnProperty(b[1].data.rows[f].id)||(m[b[1].data.rows[f].id]=f);for(i in j)j.hasOwnProperty(i)&&(g=m.hasOwnProperty(i)&&d.check_modification,h=!m.hasOwnProperty(i)&&d.check_creation,(g===!0||h===!0)&&(d.use_bulk_get===!0?(k.push({method:"get",parameter_list:[i]}),l.push({is_creation:h,is_modification:g})):t(e,a,c,i,d.conflict_force,d.conflict_revert,d.conflict_ignore,h,g,a.get.bind(a),d)));if(d.check_deletion===!0)for(i in m)m.hasOwnProperty(i)&&(j.hasOwnProperty(i)||s(e,c,i,a,d.conflict_force,d.conflict_revert,d.conflict_ignore,d));d.use_bulk_get===!0&&0!==k.length&&u(e,a,c,k,l,d,d.conflict_force,d.conflict_revert,d.conflict_ignore)})}var w=this,x=arguments,y={};return y[w._signature_hash]=null,(new b.Queue).push(function(){return w._signature_sub_storage.__storage._sub_storage.get(w._signature_hash)}).push(void 0,function(b){if(b instanceof a.util.jIOError&&404===b.status_code)return w._signature_sub_storage.__storage._sub_storage.put(w._signature_hash,{});throw b}).push(function(){return b.all([w._local_sub_storage.repair.apply(w._local_sub_storage,x),w._remote_sub_storage.repair.apply(w._remote_sub_storage,x)])}).push(function(){return w._check_local_modification||w._check_local_creation||w._check_local_deletion?v(w._local_sub_storage,w._remote_sub_storage,{use_post:w._use_remote_post,conflict_force:w._conflict_handling===j,conflict_revert:w._conflict_handling===k,conflict_ignore:w._conflict_handling===l,check_modification:w._check_local_modification,check_creation:w._check_local_creation,check_deletion:w._check_local_deletion}):void 0}).push(function(){var b=!1;try{b=w._remote_sub_storage.hasCapacity("bulk_get")}catch(c){if(!(c instanceof a.util.jIOError&&501===c.status_code))throw c}return w._check_remote_modification||w._check_remote_creation||w._check_remote_deletion?v(w._remote_sub_storage,w._local_sub_storage,{use_bulk_get:b,use_revert_post:w._use_remote_post,conflict_force:w._conflict_handling===k,conflict_revert:w._conflict_handling===j,conflict_ignore:w._conflict_handling===l,check_modification:w._check_remote_modification,check_creation:w._check_remote_creation,check_deletion:w._check_remote_deletion}):void 0}).push(function(){return w._check_local_attachment_modification||w._check_local_attachment_creation||w._check_local_attachment_deletion||w._check_remote_attachment_modification||w._check_remote_attachment_creation||w._check_remote_attachment_deletion?w._signature_sub_storage.allDocs().push(function(a){function c(a){e.push(function(){return o(a)})}var d,e=new b.Queue;for(d=0;d<a.data.total_rows;d+=1)c(a.data.rows[d].id);return e}):void 0})},a.addStorage("replicate",g)}(jIO,RSVP,Rusha,jIO.util.stringify),function(a){"use strict";function b(b){this._sub_storage=a.createJIO(b.sub_storage)}b.prototype.get=function(){return this._sub_storage.get.apply(this._sub_storage,arguments)},b.prototype.allAttachments=function(){return this._sub_storage.allAttachments.apply(this._sub_storage,arguments)},b.prototype.post=function(a){function b(){return("0000"+Math.floor(65536*Math.random()).toString(16)).slice(-4)}var c=b()+b()+"-"+b()+"-"+b()+"-"+b()+"-"+b()+b()+b();return this.put(c,a)},b.prototype.put=function(){return this._sub_storage.put.apply(this._sub_storage,arguments)},b.prototype.remove=function(){return this._sub_storage.remove.apply(this._sub_storage,arguments)},b.prototype.getAttachment=function(){return this._sub_storage.getAttachment.apply(this._sub_storage,arguments)},b.prototype.putAttachment=function(){return this._sub_storage.putAttachment.apply(this._sub_storage,arguments)},b.prototype.removeAttachment=function(){return this._sub_storage.removeAttachment.apply(this._sub_storage,arguments)},b.prototype.repair=function(){return this._sub_storage.repair.apply(this._sub_storage,arguments)},b.prototype.hasCapacity=function(a){return this._sub_storage.hasCapacity(a)},b.prototype.buildQuery=function(){return this._sub_storage.buildQuery.apply(this._sub_storage,arguments)},a.addStorage("uuid",b)}(jIO),function(a,b,c){"use strict";function d(){this._database={}}d.prototype.put=function(a,c){return this._database.hasOwnProperty(a)||(this._database[a]={attachments:{}}),this._database[a].doc=b.stringify(c),a},d.prototype.get=function(c){try{return b.parse(this._database[c].doc)}catch(d){if(d instanceof TypeError)throw new a.util.jIOError("Cannot find document: "+c,404);throw d}},d.prototype.allAttachments=function(b){var c,d={};try{for(c in this._database[b].attachments)this._database[b].attachments.hasOwnProperty(c)&&(d[c]={})}catch(e){if(e instanceof TypeError)throw new a.util.jIOError("Cannot find document: "+b,404);throw e}return d},d.prototype.remove=function(a){return delete this._database[a],a},d.prototype.getAttachment=function(b,c){try{var d=this._database[b].attachments[c];if(void 0===d)throw new a.util.jIOError("Cannot find attachment: "+b+" , "+c,404);return a.util.dataURItoBlob(d)}catch(e){if(e instanceof TypeError)throw new a.util.jIOError("Cannot find attachment: "+b+" , "+c,404);throw e}},d.prototype.putAttachment=function(b,d,e){var f;try{f=this._database[b].attachments}catch(g){if(g instanceof TypeError)throw new a.util.jIOError("Cannot find document: "+b,404);throw g}return(new c.Queue).push(function(){return a.util.readBlobAsDataURL(e)}).push(function(a){f[d]=a.target.result})},d.prototype.removeAttachment=function(b,c){try{delete this._database[b].attachments[c]}catch(d){if(d instanceof TypeError)throw new a.util.jIOError("Cannot find document: "+b,404);throw d}},d.prototype.hasCapacity=function(a){return"list"===a||"include"===a},d.prototype.buildQuery=function(a){var c,d=[];for(c in this._database)this._database.hasOwnProperty(c)&&(a.include_docs===!0?d.push({id:c,value:{},doc:b.parse(this._database[c].doc)}):d.push({id:c,value:{}}));return d},a.addStorage("memory",d)}(jIO,JSON,RSVP),function(a,b,c,d,e,f,g,h){"use strict";function i(b){return(new d.Queue).push(function(){return a.util.ajax({type:"GET",url:b._url,xhrFields:{withCredentials:b._thisCredentials},headers:b._headers})}).push(function(a){return JSON.parse(a.target.responseText)})}function j(c,e,f){return void 0===f&&(f={}),i(c).push(function(g){return(new d.Queue).push(function(){return a.util.ajax({type:"GET",url:b.parse(g._links.traverse.href).expand({relative_url:e,view:f._view}),xhrFields:{withCredentials:c._thisCredentials},headers:c._headers})}).push(void 0,function(b){if(void 0!==b.target&&404===b.target.status)throw new a.util.jIOError("Cannot find document: "+e,404);throw b})})}function k(a){return(new d.Queue).push(function(){var b,c,d,f,g=a._embedded._view,h={portal_type:a._links.type.name},i={};a._links.hasOwnProperty("parent")&&(h.parent_relative_url=new e(a._links.parent.href).segment(2)),i.form_id={key:[g.form_id.key],"default":g.form_id["default"]};for(c in g)g.hasOwnProperty(c)&&(b=g[c],d=0,0===c.indexOf("my_")&&b.editable&&(d=3),0===c.indexOf("your_")&&(d=5),0!==d&&q.hasOwnProperty(b.type)&&(i[c.substring(d)]={"default":b["default"],key:b.key},h[c.substring(d)]=b["default"]));return f={data:h,form_data:i},g.hasOwnProperty("_actions")&&g._actions.hasOwnProperty("put")&&(f.action_href=g._actions.put.href),f})}function l(b,c){return b.getAttachment(c,"view").push(function(b){return a.util.readBlobAsText(b)}).push(function(a){return JSON.parse(a.target.result)}).push(function(a){return k(a)})}function m(a){if("string"!=typeof a.url||!a.url)throw new TypeError("ERP5 'url' must be a string which contains more than one character.");this._url=a.url,this._default_view_reference=a.default_view_reference,this._headers=null,this._thisCredentials=!0,void 0!==a.login&&void 0!==a.password&&(this._headers={Authorization:"Basic "+btoa(a.login+":"+a.password)},this._thisCredentials=!1)}function n(a){return a.data}function o(a){return a instanceof g&&"local_roles"===a.key?a.value:void 0}function p(a){var b,c,d=!0,e=[];if(a instanceof h&&"OR"===a.operator){for(b=0;b<a.query_list.length;b+=1)c=a.query_list[b],c instanceof g&&"local_roles"===c.key?e.push(c.value):d=!1;if(d)return e}}var q={StringField:null,EmailField:null,IntegerField:null,FloatField:null,TextAreaField:null};m.prototype.get=function(a){return l(this,a).push(function(a){return n(a)})},m.prototype.bulk=function(b){var e,f=this,g=[];for(e=0;e<b.length;e+=1){if("get"!==b[e].method)throw new Error("ERP5Storage: not supported "+b[e].method+" in bulk");g.push({relative_url:b[e].parameter_list[0],view:f._default_view_reference})}return i(f).push(function(b){var d=new c;return d.append("bulk_list",JSON.stringify(g)),a.util.ajax({type:"POST",url:b._actions.bulk.href,data:d,xhrFields:{withCredentials:f._thisCredentials},headers:f._headers})}).push(function(a){function b(a){return k(a).push(function(a){return n(a)})}var c=[],f=JSON.parse(a.target.responseText);for(e=0;e<f.result_list.length;e+=1)c.push(b(f.result_list[e]));return d.all(c)})},m.prototype.post=function(b){var d,f=this;return i(this).push(function(d){var e=new c;return e.append("portal_type",b.portal_type),e.append("parent_relative_url",b.parent_relative_url),a.util.ajax({type:"POST",url:d._actions.add.href,data:e,xhrFields:{withCredentials:f._thisCredentials},headers:f._headers})}).push(function(a){var c=a.target.getResponseHeader("X-Location"),g=new e(c);return d=g.segment(2),f.put(d,b)}).push(function(){return d})},m.prototype.put=function(b,c){var d=this;return l(d,b).push(function(e){var g,h=e.form_data,i={};i[h.form_id.key]=h.form_id["default"];for(g in c)if(c.hasOwnProperty(g)){if("form_id"===g)throw new a.util.jIOError("ERP5: forbidden property: "+g,400);if("portal_type"!==g&&"parent_relative_url"!==g){if(!h.hasOwnProperty(g))throw new a.util.jIOError("ERP5: can not store property: "+g,400);i[h[g].key]=c[g]}}if(!e.hasOwnProperty("action_href"))throw new a.util.jIOError("ERP5: can not modify document: "+b,403);return d.putAttachment(b,e.action_href,new f([JSON.stringify(i)],{type:"application/json"}))})},m.prototype.allAttachments=function(a){var b=this;return j(this,a).push(function(){return void 0===b._default_view_reference?{links:{}}:{view:{},links:{}}})},m.prototype.getAttachment=function(b,c,e){var g=this;if(void 0===e&&(e={}),"view"===c){if(void 0===this._default_view_reference)throw new a.util.jIOError("Cannot find attachment view for: "+b,404);return j(this,b,{_view:this._default_view_reference}).push(function(a){var b=JSON.parse(a.target.responseText);return new f([JSON.stringify(b)],{type:"application/hal+json"})})}if("links"===c)return j(this,b).push(function(a){return new f([JSON.stringify(JSON.parse(a.target.responseText))],{type:"application/hal+json"})});if(0===c.indexOf(this._url))return(new d.Queue).push(function(){var b,d,f,h={type:"GET",dataType:"blob",url:c,xhrFields:{withCredentials:g._thisCredentials},headers:g._headers};if(void 0!==e.start||void 0!==e.end){if(b=e.start||0,d=e.end,void 0!==d&&0>d)throw new a.util.jIOError("end must be positive",400);if(0>b)f="bytes="+b;else if(void 0===d)f="bytes="+b+"-";else{if(b>d)throw new a.util.jIOError("start is greater than end",400);f="bytes="+b+"-"+d}void 0===g._headers?h.headers={Range:f}:h.headers.Range=f}return a.util.ajax(h)}).push(function(a){return void 0===a.target.response?new f([a.target.responseText],{type:a.target.getResponseHeader("Content-Type")}):a.target.response});throw new a.util.jIOError("ERP5: not support get attachment: "+c,400)},m.prototype.putAttachment=function(b,e,f){var g=this;if(0!==e.indexOf(this._url))throw new a.util.jIOError("Can not store outside ERP5: "+e,400);return(new d.Queue).push(function(){return a.util.readBlobAsText(f)}).push(function(b){var d,f,h,i,j=JSON.parse(b.target.result),k=new c;for(h in j)if(j.hasOwnProperty(h))for(d=Array.isArray(j[h])?j[h]:[j[h]],f=0;f<d.length;f+=1)i=d[f],"object"==typeof i?k.append(h,a.util.dataURItoBlob(i.url),i.file_name):k.append(h,i);return a.util.ajax({type:"POST",url:e,data:k,xhrFields:{withCredentials:g._thisCredentials},headers:g._headers})})},m.prototype.hasCapacity=function(a){return"list"===a||"query"===a||"select"===a||"limit"===a||"sort"===a||"bulk_get"===a},m.prototype.buildQuery=function(c){var d=this;return i(this).push(function(e){var f,g,i,j,k,l=c.query,m=[];if(c.query)if(g=a.QueryFactory.create(c.query),j=o(g))l=void 0,k=j;else if(j=p(g))l=void 0,k=j;else if(g instanceof h&&"AND"===g.operator)for(f=0;f<g.query_list.length;f+=1)i=g.query_list[f],j=o(i),j?(k=j,g.query_list.splice(f,1),l=a.Query.objectToSearchText(g),f=g.query_list.length):(j=p(i),j&&(k=j,g.query_list.splice(f,1),l=a.Query.objectToSearchText(g),f=g.query_list.length));if(c.sort_on)for(f=0;f<c.sort_on.length;f+=1)m.push(JSON.stringify(c.sort_on[f]));return a.util.ajax({type:"GET",url:b.parse(e._links.raw_search.href).expand({query:l,select_list:c.select_list||["title","reference"],limit:c.limit,sort_on:m,local_roles:k}),xhrFields:{withCredentials:d._thisCredentials},headers:d._headers})}).push(function(a){return JSON.parse(a.target.responseText)}).push(function(a){var b,c,d,f=a._embedded.contents,g=f.length,h=[];for(b=0;g>b;b+=1)d=f[b],c=new e(d._links.self.href),delete d._links,h.push({id:c.segment(2),value:d});return h})},a.addStorage("erp5",m)}(jIO,UriTemplate,FormData,RSVP,URI,Blob,SimpleQuery,ComplexQuery),function(a,b,c,d,e){"use strict";function f(b){this._sub_storage=a.createJIO(b.sub_storage),this._document_id=b.document_id,this._repair_attachment=b.repair_attachment||!1}function g(a,b){return void 0===b?"jio_document/"+d(a)+h:"jio_attachment/"+d(a)+"/"+d(b)}var h=".json",i=new RegExp("^jio_document/([\\w=]+)"+h+"$"),j=new RegExp("^jio_attachment/([\\w=]+)/([\\w=]+)$");f.prototype.get=function(a){return this._sub_storage.getAttachment(this._document_id,g(a),{format:"json"})},f.prototype.allAttachments=function(a){return this._sub_storage.allAttachments(this._document_id).push(function(b){var d,e,f={};for(e in b)if(b.hasOwnProperty(e)&&j.test(e)){d=j.exec(e);try{c(d[1])===a&&(f[c(d[2])]={})}catch(g){if(!g instanceof ReferenceError)throw g}}return f})},f.prototype.put=function(a,c){return this._sub_storage.putAttachment(this._document_id,g(a),new b([JSON.stringify(c)],{type:"application/json"})).push(function(){return a})},f.prototype.remove=function(a){var b=this;return this.allAttachments(a).push(function(c){var d,f=[];for(d in c)c.hasOwnProperty(d)&&f.push(b.removeAttachment(a,d));return e.all(f)}).push(function(){return b._sub_storage.removeAttachment(b._document_id,g(a))}).push(function(){return a})},f.prototype.repair=function(){var a=this;return this._sub_storage.repair.apply(this._sub_storage,arguments).push(function(b){return a._repair_attachment?a._sub_storage.allAttachments(a._document_id).push(function(b){var d,f,g,h,k=[],l={},m={};for(h in b)if(b.hasOwnProperty(h))if(d=void 0,f=void 0,i.test(h)){try{d=c(i.exec(h)[1])}catch(n){if(!n instanceof ReferenceError)throw n}void 0!==d&&(l[d]=null)}else if(j.test(h)){g=j.exec(h);try{d=c(g[1]),f=c(g[2])}catch(n){if(!n instanceof ReferenceError)throw n}void 0!==f&&(l.hasOwnProperty(d)||(m.hasOwnProperty(d)||(m[d]={}),m[d][f]=null))}for(d in m)if(m.hasOwnProperty(d)&&!l.hasOwnProperty(d))for(f in m[d])m[d].hasOwnProperty(f)&&k.push(a.removeAttachment(d,f));return e.all(k)}):b})},f.prototype.hasCapacity=function(a){return"list"===a},f.prototype.buildQuery=function(){return this._sub_storage.allAttachments(this._document_id).push(function(a){var b,d=[];for(b in a)if(a.hasOwnProperty(b)&&i.test(b))try{d.push({id:c(i.exec(b)[1]),value:{}})}catch(e){if(!e instanceof ReferenceError)throw e}return d})},f.prototype.getAttachment=function(a,b){return this._sub_storage.getAttachment(this._document_id,g(a,b))},f.prototype.putAttachment=function(a,b,c){return this._sub_storage.putAttachment(this._document_id,g(a,b),c)},f.prototype.removeAttachment=function(a,b){return this._sub_storage.removeAttachment(this._document_id,g(a,b))},a.addStorage("document",f)}(jIO,Blob,atob,btoa,RSVP),function(a,b){"use strict";function c(b){this._sub_storage=a.createJIO(b.sub_storage),this._key_schema=b.key_schema}c.prototype.get=function(){return this._sub_storage.get.apply(this._sub_storage,arguments)},c.prototype.allAttachments=function(){return this._sub_storage.allAttachments.apply(this._sub_storage,arguments)},c.prototype.post=function(){return this._sub_storage.post.apply(this._sub_storage,arguments)},c.prototype.put=function(){return this._sub_storage.put.apply(this._sub_storage,arguments)},c.prototype.remove=function(){return this._sub_storage.remove.apply(this._sub_storage,arguments)},c.prototype.getAttachment=function(){return this._sub_storage.getAttachment.apply(this._sub_storage,arguments)},c.prototype.putAttachment=function(){return this._sub_storage.putAttachment.apply(this._sub_storage,arguments)},c.prototype.removeAttachment=function(){return this._sub_storage.removeAttachment.apply(this._sub_storage,arguments)},c.prototype.repair=function(){return this._sub_storage.repair.apply(this._sub_storage,arguments)},c.prototype.hasCapacity=function(a){var b=["limit","sort","select","query"];return-1!==b.indexOf(a)?!0:"list"===a?this._sub_storage.hasCapacity(a):!1},c.prototype.buildQuery=function(c){var d=this._sub_storage,e=this,f={},g=!1,h=!1;if(d.hasCapacity("list")){try{void 0!==c.query&&!d.hasCapacity("query")||void 0!==c.sort_on&&!d.hasCapacity("sort")||void 0!==c.select_list&&!d.hasCapacity("select")||void 0!==c.limit&&!d.hasCapacity("limit")||(f.query=c.query,f.sort_on=c.sort_on,f.select_list=c.select_list,f.limit=c.limit)}catch(i){if(!(i instanceof a.util.jIOError&&501===i.status_code))throw i;g=!0}try{(g||c.include_docs===!0)&&d.hasCapacity("include")&&(f.include_docs=!0)}catch(i){if(!(i instanceof a.util.jIOError&&501===i.status_code))throw i;h=!0}return d.buildQuery(f).push(function(c){function e(b){var e=c[b].id;return d.get(e).push(function(a){return a._id=e,a},function(b){if(!(b instanceof a.util.jIOError&&404===b.status_code))throw b})}var f,g,i=[c];if(h){for(f=c.length,g=0;f>g;g+=1)i.push(e(g));c=b.all(i)}return c}).push(function(a){var b,c,d;if(h){for(b=a[0],c=b.length,d=0;c>d;d+=1)b[d].doc=a[d+1];a=b}return a}).push(function(b){var d,f,h=[];if(g){for(d=b.length,f=0;d>f;f+=1)b[f].doc.__id=b[f].id,h.push(b[f].doc);c.select_list&&c.select_list.push("__id"),b=a.QueryFactory.create(c.query||"",e._key_schema).exec(h,c)}return b}).push(function(a){var b,d,e,f=[];if(g){for(d=a.length,e=0;d>e;e+=1){if(b={id:a[e].__id,value:c.select_list?a[e]:{},doc:{}},c.select_list&&delete b.value.__id,c.include_docs)throw new Error("QueryStorage does not support include docs");f.push(b)}a=f}return a})}},a.addStorage("query",c)}(jIO,RSVP),function(a,b,c,d){"use strict";function e(a){a.sessiononly===!0?this._storage=b:this._storage=c}function f(b){if("/"!==b)throw new a.util.jIOError("id "+b+" is forbidden (!== /)",400)}e.prototype.get=function(a){return f(a),{}},e.prototype.allAttachments=function(a){f(a);var b,c={};for(b in this._storage)this._storage.hasOwnProperty(b)&&(c[b]={});return c},e.prototype.getAttachment=function(b,c){f(b);var d=this._storage.getItem(c);if(null===d)throw new a.util.jIOError("Cannot find attachment "+c,404);return a.util.dataURItoBlob(d)},e.prototype.putAttachment=function(b,c,e){var g=this;return f(b),(new d.Queue).push(function(){return a.util.readBlobAsDataURL(e)}).push(function(a){g._storage.setItem(c,a.target.result)})},e.prototype.removeAttachment=function(a,b){return f(a),this._storage.removeItem(b)},e.prototype.hasCapacity=function(a){return"list"===a},e.prototype.buildQuery=function(){return[{id:"/",value:{}}]},a.addStorage("local",e)}(jIO,sessionStorage,localStorage,RSVP),function(a,b,c,d,e,f,g){"use strict";function h(b){var c,g=[];for(c in b._mapping_dict)if(b._mapping_dict.hasOwnProperty(c)){if("equalValue"===b._mapping_dict[c][0]){if(void 0===b._mapping_dict[c][1])throw new a.util.jIOError("equalValue has not parameter",400);b._default_mapping[c]=b._mapping_dict[c][1],g.push(new d({key:c,value:b._mapping_dict[c][1],type:"simple"}))}if("equalSubId"===b._mapping_dict[c][0]){if(void 0!==b._property_for_sub_id)throw new a.util.jIOError("equalSubId can be defined one time",400);b._property_for_sub_id=c}}void 0!==b._query.query&&g.push(f.create(b._query.query)),g.length>1?b._query.query=new e({type:"complex",query_list:g,operator:"AND"}):1===g.length&&(b._query.query=g[0])}function i(b){this._mapping_dict=b.mapping_dict||{},this._sub_storage=a.createJIO(b.sub_storage),this._map_all_property=void 0!==b.map_all_property?b.map_all_property:!0,this._attachment_mapping_dict=b.attachment_mapping_dict||{},this._query=b.query||{},this._map_id=b.map_id,this._id_mapped=void 0!==b.map_id?b.map_id[1]:!1,void 0!==this._query.query&&(this._query.query=f.create(this._query.query)),this._default_mapping={},h(this)}function j(a,b,d,e){var f=a._attachment_mapping_dict;return void 0!==f&&void 0!==f[d]&&void 0!==f[d][e]&&void 0!==f[d][e].uri_template?c.parse(f[d][e].uri_template).expand({id:b}):d}function k(c,f,h){var i;return(new b.Queue).push(function(){if(void 0!==c._property_for_sub_id&&void 0!==h&&void 0!==h[c._property_for_sub_id])return h[c._property_for_sub_id];if(!c._id_mapped)return f;if("equalSubProperty"===c._map_id[0])return i=new d({key:c._map_id[1],value:f,type:"simple"}),void 0!==c._query.query&&(i=new e({operator:"AND",query_list:[i,c._query.query],type:"complex"})),i=g.objectToSearchText(i),c._sub_storage.allDocs({query:i,sort_on:c._query.sort_on,select_list:c._query.select_list,limit:c._query.limit}).push(function(b){if(0===b.data.rows.length)throw new a.util.jIOError("Can not find id",404);if(b.data.rows.length>1)throw new TypeError("id must be unique field: "+f+", result:"+b.data.rows.toString());return b.data.rows[0].id});throw new a.util.jIOError("Unsuported option: "+c._mapping_dict.id,400)})}function l(b,c,d,e){var f,g;if(void 0!==b._mapping_dict[c]){if(f=b._mapping_dict[c][0],g=b._mapping_dict[c][1],"equalSubProperty"===f)return d[g]=e[c],g;if("equalValue"===f)return d[c]=g,c;if("ignore"===f||"equalSubId"===f)return!1}if(!b._map_all_property)return!1;if(b._map_all_property)return d[c]=e[c],c;throw new a.util.jIOError("Unsuported option(s): "+b._mapping_dict[c],400)}function m(a,b,c,d){var e,f;if(void 0!==a._mapping_dict[b]){if(e=a._mapping_dict[b][0],f=a._mapping_dict[b][1],"equalSubProperty"===e)return c.hasOwnProperty(f)&&(d[b]=c[f]),f;if("equalValue"===e)return b;if("ignore"===e)return b}return a._map_all_property?(c.hasOwnProperty(b)&&(d[b]=c[b]),b):!1}function n(a,b,c){var d,e={},f=[a._id_mapped];for(d in a._mapping_dict)a._mapping_dict.hasOwnProperty(d)&&f.push(m(a,d,b,e));if(a._map_all_property)for(d in b)b.hasOwnProperty(d)&&f.indexOf(d)<0&&(e[d]=b[d]);return void 0!==a._property_for_sub_id&&void 0!==c&&(e[a._property_for_sub_id]=c),e}function o(a,b,c){var d,e={};for(d in b)b.hasOwnProperty(d)&&l(a,d,e,b);for(d in a._default_mapping)a._default_mapping.hasOwnProperty(d)&&(e[d]=a._default_mapping[d]);return a._id_mapped&&void 0!==c&&(e[a._id_mapped]=c),e}function p(a,b,c){return k(a,b[0]).push(function(d){return b[0]=d,b[1]=j(a,d,b[1],c),a._sub_storage[c+"Attachment"].apply(a._sub_storage,b)})}i.prototype.get=function(a){var b=this;return k(this,a).push(function(a){return b._sub_storage.get(a).push(function(c){return n(b,c,a)})})},i.prototype.post=function(b){var c=o(this,b),d=b[this._property_for_sub_id];if(this._property_for_sub_id&&void 0!==d)return this._sub_storage.put(d,c);if(!this._id_mapped||void 0!==b[this._id_mapped])return this._sub_storage.post(c);throw new a.util.jIOError("post is not supported with id mapped",400)},i.prototype.put=function(b,c){var d=this,e=o(this,c,b);return k(this,b,c).push(function(a){return d._sub_storage.put(a,e)}).push(void 0,function(b){if(b instanceof a.util.jIOError&&404===b.status_code)return d._sub_storage.post(e);throw b}).push(function(){return b})},i.prototype.remove=function(a){var b=this;return k(this,a).push(function(a){return b._sub_storage.remove(a)}).push(function(){return a})},i.prototype.putAttachment=function(a,b){return p(this,arguments,"put",a).push(function(){return b})},i.prototype.getAttachment=function(){return p(this,arguments,"get")},i.prototype.removeAttachment=function(a,b){return p(this,arguments,"remove",a).push(function(){return b})},i.prototype.allAttachments=function(a){var b,c=this;return k(c,a).push(function(a){return b=a,c._sub_storage.allAttachments(b)}).push(function(a){var d,e={},f={};for(d in c._attachment_mapping_dict)c._attachment_mapping_dict.hasOwnProperty(d)&&(f[j(c,b,d,"get")]=d);for(d in a)a.hasOwnProperty(d)&&(f.hasOwnProperty(d)?e[f[d]]={}:e[d]={});return e})},i.prototype.hasCapacity=function(a){return this._sub_storage.hasCapacity(a)},i.prototype.repair=function(){return this._sub_storage.repair.apply(this._sub_storage,arguments)},i.prototype.bulk=function(a){function c(a){return k(d,a.parameter_list[0]).push(function(b){return{method:a.method,parameter_list:[b]}})}var d=this;return(new b.Queue).push(function(){var d=a.map(c);return b.all(d)}).push(function(a){return d._sub_storage.bulk(a)}).push(function(a){var b,c=[];for(b=0;b<a.length;b+=1)c.push(n(d,a[b]));return c})},i.prototype.buildQuery=function(a){function b(a){var c,d,e,f=[];if("complex"===a.type){for(c=0;c<a.query_list.length;c+=1)e=b(a.query_list[c]),e&&f.push(e);return a.query_list=f,a}return d=m(i,a.key,{},{}),
d?(a.key=d,a):!1}var c,d,h,i=this,j=[],k=[];if(void 0!==a.sort_on)for(c=0;c<a.sort_on.length;c+=1)h=m(this,a.sort_on[c][0],{},{}),h&&k.indexOf(h)<0&&k.push([h,a.sort_on[c][1]]);if(void 0!==this._query.sort_on)for(c=0;c<this._query.sort_on.length;c+=1)h=m(this,this._query.sort_on[c],{},{}),k.indexOf(h)<0&&k.push([h,a.sort_on[c][1]]);if(void 0!==a.select_list)for(c=0;c<a.select_list.length;c+=1)h=m(this,a.select_list[c],{},{}),h&&j.indexOf(h)<0&&j.push(h);if(void 0!==this._query.select_list)for(c=0;c<this._query.select_list;c+=1)h=this._query.select_list[c],j.indexOf(h)<0&&j.push(h);return this._id_mapped&&j.push(this._id_mapped),void 0!==a.query&&(d=b(f.create(a.query))),void 0!==this._query.query&&(void 0===d&&(d=this._query.query),d=new e({operator:"AND",query_list:[d,this._query.query],type:"complex"})),void 0!==d&&(d=g.objectToSearchText(d)),this._sub_storage.allDocs({query:d,select_list:j,sort_on:k,limit:a.limit}).push(function(a){var b;for(c=0;c<a.data.total_rows;c+=1)b=a.data.rows[c].value,a.data.rows[c].value=n(i,b),i._id_mapped&&(a.data.rows[c].id=b[i._id_mapped]);return a.data.rows})},a.addStorage("mapping",i)}(jIO,RSVP,UriTemplate,SimpleQuery,ComplexQuery,QueryFactory,Query);
\ No newline at end of file
{
"name": "jio",
"version": "1.0.0",
"description": "jIO for nodejs",
"main": "jio.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://lab.nexedi.com/nexedi/jio"
},
"keywords": [
"jio"
],
"author": "Aurélien Calonne",
"license": "ISC"
}
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"name": "moment",
"version": "1.0.0",
"description": "",
"main": "moment-2.13.0.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
{
"//1": "describes your app and its dependencies",
"//2": "https://docs.npmjs.com/files/package.json",
"//3": "updating this file will download and update your packages",
"name": "clearroad-nodejs",
"version": "0.0.1",
"description": "ClearRoad API on Node.js",
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"dependencies": {
"express": "^4.14.1",
"stream-buffer": "latest",
"xhr2": "latest",
"rsvp": "git+https://lab.nexedi.com/nexedi/rsvp.js.git",
"uritemplate": "latest",
"moment": "file:lib/moment",
"navigator": "latest",
"rusha": "latest",
"form-data": "latest",
"atob": "latest",
"html5": "file:lib/html5",
"node-localstorage": "latest",
"btoa": "latest",
"xhr2": "latest",
"stream-buffers": "latest",
"clearroad": "file:lib/clearroad",
"jio": "file:lib/jio",
"urijs": "latest"
},
"engines": {
"node": "6.9.x"
},
"repository": {
"url": ""
},
"license": "",
"keywords": [
"node",
"jio",
"clearroad"
]
}
......@@ -14,6 +14,7 @@ global.Blob = require("html5").Blob;
global.localStorage = require('node-localstorage');
global.btoa = require('btoa');
global.XMLHttpRequest = require('xhr2');
global.StreamBuffers = require('stream-buffers');
global.window = global;
global.sessionStorage = {};
......@@ -24,7 +25,7 @@ var ClearRoadBillingPeriodRegistration = require("clearroad");
var cr = new ClearRoadBillingPeriodRegistration();
console.log("init");
cr.post({
"reference" : "Q42",
"reference" : "Q421",
"start_date" : "2017-02-01T00:00:00Z",
"stop_date" : "2017-03-01T00:00:00Z"
}).push(function (){
......
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