Commit b9395035 authored by Romain Courteaud's avatar Romain Courteaud

Release 3.38.0

Fix query.

Improve IndexedDB storage.

Improve ajax in node.
parent 1ffefba4
...@@ -26,7 +26,7 @@ TESTDIR = test ...@@ -26,7 +26,7 @@ TESTDIR = test
EXAMPLEDIR = examples EXAMPLEDIR = examples
EXTERNALDIR = external EXTERNALDIR = external
VERSION = 3.37.0 VERSION = 3.38.0
JIOVERSION = ${DISTDIR}/jio-v${VERSION}.js JIOVERSION = ${DISTDIR}/jio-v${VERSION}.js
JIOLATEST = ${DISTDIR}/jio-latest.js JIOLATEST = ${DISTDIR}/jio-latest.js
JIONODEVERSION = ${DISTDIR}/jio-v${VERSION}-node.js JIONODEVERSION = ${DISTDIR}/jio-v${VERSION}-node.js
......
...@@ -7883,6 +7883,8 @@ var arrayExtend = function () { ...@@ -7883,6 +7883,8 @@ var arrayExtend = function () {
return true; return true;
} }
return false; return false;
}, parseQuotedString = function (string) {
return string.replace(/(?:\\(")|(\\[^"]))/g, '$1$2');
}, },
error_offsets = [], error_offsets = [],
error_lookaheads = [], error_lookaheads = [],
...@@ -8004,7 +8006,7 @@ case 17: ...@@ -8004,7 +8006,7 @@ case 17:
this.$ = mkSimpleQuery('', $$[$0]); this.$ = mkSimpleQuery('', $$[$0]);
break; break;
case 18: case 18:
this.$ = mkSimpleQuery('', $$[$0-1]); this.$ = mkSimpleQuery('', parseQuotedString($$[$0-1]));
break; break;
} }
}, },
...@@ -8708,6 +8710,9 @@ return new Parser; ...@@ -8708,6 +8710,9 @@ return new Parser;
throw new TypeError("jioquery.sortOn(): " + throw new TypeError("jioquery.sortOn(): " +
"Argument 1 is not of type 'array'"); "Argument 1 is not of type 'array'");
} }
if (sort_on_option.length === 0) {
return list;
}
list.sort(generateSortFunction( list.sort(generateSortFunction(
key_schema, key_schema,
sort_on_option sort_on_option
...@@ -9223,6 +9228,16 @@ return new Parser; ...@@ -9223,6 +9228,16 @@ return new Parser;
"Argument 1 is not a search text or a parsable object"); "Argument 1 is not a search text or a parsable object");
}; };
function ensureString(value) {
if (value === undefined) { return "undefined"; }
if (value === null) { return "null"; }
return value.toString();
}
function renderSearchTextValue(value) {
return '"' + ensureString(value).replace(/"/g, '\\"') + '"';
}
function objectToSearchText(query) { function objectToSearchText(query) {
var i = 0, var i = 0,
query_list = null, query_list = null,
...@@ -9231,7 +9246,8 @@ return new Parser; ...@@ -9231,7 +9246,8 @@ return new Parser;
common_key = ""; common_key = "";
if (query.type === "simple") { if (query.type === "simple") {
return (query.key ? query.key + ": " : "") + return (query.key ? query.key + ": " : "") +
(query.operator || "") + ' "' + query.value + '"'; (query.operator || "") + ' ' +
renderSearchTextValue(query.value);
} }
if (query.type === "complex") { if (query.type === "complex") {
query_list = query.query_list; query_list = query.query_list;
...@@ -9262,7 +9278,7 @@ return new Parser; ...@@ -9262,7 +9278,7 @@ return new Parser;
for (i = 0; i < query_list.length; i += 1) { for (i = 0; i < query_list.length; i += 1) {
string_list.push( string_list.push(
(query_list[i].operator || "") + (query_list[i].operator || "") +
' "' + query_list[i].value + '"' ' ' + renderSearchTextValue(query_list[i].value)
); );
} }
} else { } else {
...@@ -9849,11 +9865,10 @@ return new Parser; ...@@ -9849,11 +9865,10 @@ return new Parser;
try { try {
return window.atob(str); return window.atob(str);
} catch (err) { } catch (err) {
var buffer; var buffer = Buffer.from(str.toString(), 'base64');
if (str instanceof Buffer) { // Provide the same behaviour than the browser atob
buffer = str; if (buffer.toString('base64') !== str) {
} else { throw new Error('The string to be decoded is not correctly encoded.');
buffer = Buffer.from(str.toString(), 'base64');
} }
return buffer.toString('binary'); return buffer.toString('binary');
} }
...@@ -9865,13 +9880,7 @@ return new Parser; ...@@ -9865,13 +9880,7 @@ return new Parser;
try { try {
return window.btoa(str); return window.btoa(str);
} catch (err) { } catch (err) {
var buffer; return Buffer.from(str.toString(), 'binary').toString('base64');
if (str instanceof Buffer) {
buffer = str;
} else {
buffer = Buffer.from(str.toString(), 'binary');
}
return buffer.toString('base64');
} }
} }
...@@ -9879,8 +9888,8 @@ return new Parser; ...@@ -9879,8 +9888,8 @@ return new Parser;
}(window, WeakMap, ArrayBuffer, Uint8Array)); }(window, WeakMap, ArrayBuffer, Uint8Array));
var XMLHttpRequest = global.XMLHttpRequest || module.exports, global.XMLHttpRequest = module.exports;
Blob = window.Blob, var Blob = window.Blob,
atob = window.atob, atob = window.atob,
btoa = window.btoa, btoa = window.btoa,
FileReader = window.FileReader, FileReader = window.FileReader,
...@@ -10674,7 +10683,7 @@ var XMLHttpRequest = global.XMLHttpRequest || module.exports, ...@@ -10674,7 +10683,7 @@ var XMLHttpRequest = global.XMLHttpRequest || module.exports,
*/ */
/*global window */ /*global window */
(function (window, jIO, Blob) { (function (window, jIO, Blob, RSVP) {
"use strict"; "use strict";
var FormData, var FormData,
...@@ -10696,32 +10705,71 @@ var XMLHttpRequest = global.XMLHttpRequest || module.exports, ...@@ -10696,32 +10705,71 @@ var XMLHttpRequest = global.XMLHttpRequest || module.exports,
}; };
window.FormData = FormData; window.FormData = FormData;
function convertToBlob(promise, convert) {
if (!convert) {
return promise;
}
var result;
if (promise instanceof RSVP.Queue) {
result = promise;
} else {
result = new RSVP.Queue()
.push(function () {
return promise;
});
}
return result
.push(function (evt) {
evt.target.response = new Blob(
[evt.target.response || evt.target.responseText],
{type: evt.target.getResponseHeader('Content-Type')}
);
return evt;
});
}
originalAjax = jIO.util.ajax; originalAjax = jIO.util.ajax;
jIO.util.ajax = function ajax(param) { jIO.util.ajax = function ajax(param) {
var result,
need_convertion = (param.dataType === 'blob');
// Copy the param dict document (no need for deep copy) to
// allow tests to check them
param = Object.assign({}, param);
if (need_convertion) {
param.dataType = 'arraybuffer';
}
if (param.data instanceof Blob) { if (param.data instanceof Blob) {
// Blob is not supported by xhr2, so convert to ArrayBuffer instead // Blob is not supported by xhr2, so convert to ArrayBuffer instead
return jIO.util.readBlobAsArrayBuffer(param.data).then(function (data) { result = new RSVP.Queue()
param.data = data.target.result; .push(function () {
return jIO.util.readBlobAsArrayBuffer(param.data);
})
.push(function (evt) {
param.data = evt.target.result;
return originalAjax(param); return originalAjax(param);
}); });
} } else if (param.data instanceof FormData) {
if (param.data instanceof FormData) {
// Implement minimal FormData for erp5storage // Implement minimal FormData for erp5storage
if (!param.hasOwnProperty('headers')) { if (!param.hasOwnProperty('headers')) {
param.headers = {}; param.headers = {};
} else {
// Copy the param dict document (no need for deep copy) to
// allow tests to check them
param.headers = Object.assign({}, param.headers);
} }
param.headers["Content-Type"] = "multipart\/form-data; boundary=" + param.headers["Content-Type"] = "multipart\/form-data; boundary=" +
param.data.boundary; param.data.boundary;
param.data.body += '--' + param.data.boundary + '--\r\n'; param.data.body += '--' + param.data.boundary + '--\r\n';
param.data = param.data.body; param.data = param.data.body;
return originalAjax(param); result = originalAjax(param);
} else {
result = originalAjax(param);
} }
return originalAjax(param); return convertToBlob(result, need_convertion);
}; };
}(window, window.jIO, window.Blob)); }(window, window.jIO, window.Blob, window.RSVP));
// Define a global variable to allow storages to access jIO // Define a global variable to allow storages to access jIO
var jIO = window.jIO, var jIO = window.jIO,
...@@ -12024,7 +12072,8 @@ var jIO = window.jIO, ...@@ -12024,7 +12072,8 @@ var jIO = window.jIO,
}); });
} }
report.log(id, options.from_local ? LOG_UNEXPECTED_REMOTE_ATTACHMENT : report.log(id, options.from_local ? LOG_UNEXPECTED_REMOTE_ATTACHMENT :
LOG_UNEXPECTED_LOCAL_ATTACHMENT); LOG_UNEXPECTED_LOCAL_ATTACHMENT,
JSON.stringify(attachment_dict));
}, function (error) { }, function (error) {
if ((error instanceof jIO.util.jIOError) && if ((error instanceof jIO.util.jIOError) &&
(error.status_code === 404)) { (error.status_code === 404)) {
......
...@@ -6105,6 +6105,8 @@ var arrayExtend = function () { ...@@ -6105,6 +6105,8 @@ var arrayExtend = function () {
return true; return true;
} }
return false; return false;
}, parseQuotedString = function (string) {
return string.replace(/(?:\\(")|(\\[^"]))/g, '$1$2');
}, },
error_offsets = [], error_offsets = [],
error_lookaheads = [], error_lookaheads = [],
...@@ -6226,7 +6228,7 @@ case 17: ...@@ -6226,7 +6228,7 @@ case 17:
this.$ = mkSimpleQuery('', $$[$0]); this.$ = mkSimpleQuery('', $$[$0]);
break; break;
case 18: case 18:
this.$ = mkSimpleQuery('', $$[$0-1]); this.$ = mkSimpleQuery('', parseQuotedString($$[$0-1]));
break; break;
} }
}, },
...@@ -6930,6 +6932,9 @@ return new Parser; ...@@ -6930,6 +6932,9 @@ return new Parser;
throw new TypeError("jioquery.sortOn(): " + throw new TypeError("jioquery.sortOn(): " +
"Argument 1 is not of type 'array'"); "Argument 1 is not of type 'array'");
} }
if (sort_on_option.length === 0) {
return list;
}
list.sort(generateSortFunction( list.sort(generateSortFunction(
key_schema, key_schema,
sort_on_option sort_on_option
...@@ -7445,6 +7450,16 @@ return new Parser; ...@@ -7445,6 +7450,16 @@ return new Parser;
"Argument 1 is not a search text or a parsable object"); "Argument 1 is not a search text or a parsable object");
}; };
function ensureString(value) {
if (value === undefined) { return "undefined"; }
if (value === null) { return "null"; }
return value.toString();
}
function renderSearchTextValue(value) {
return '"' + ensureString(value).replace(/"/g, '\\"') + '"';
}
function objectToSearchText(query) { function objectToSearchText(query) {
var i = 0, var i = 0,
query_list = null, query_list = null,
...@@ -7453,7 +7468,8 @@ return new Parser; ...@@ -7453,7 +7468,8 @@ return new Parser;
common_key = ""; common_key = "";
if (query.type === "simple") { if (query.type === "simple") {
return (query.key ? query.key + ": " : "") + return (query.key ? query.key + ": " : "") +
(query.operator || "") + ' "' + query.value + '"'; (query.operator || "") + ' ' +
renderSearchTextValue(query.value);
} }
if (query.type === "complex") { if (query.type === "complex") {
query_list = query.query_list; query_list = query.query_list;
...@@ -7484,7 +7500,7 @@ return new Parser; ...@@ -7484,7 +7500,7 @@ return new Parser;
for (i = 0; i < query_list.length; i += 1) { for (i = 0; i < query_list.length; i += 1) {
string_list.push( string_list.push(
(query_list[i].operator || "") + (query_list[i].operator || "") +
' "' + query_list[i].value + '"' ' ' + renderSearchTextValue(query_list[i].value)
); );
} }
} else { } else {
...@@ -10357,7 +10373,8 @@ return new Parser; ...@@ -10357,7 +10373,8 @@ return new Parser;
}); });
} }
report.log(id, options.from_local ? LOG_UNEXPECTED_REMOTE_ATTACHMENT : report.log(id, options.from_local ? LOG_UNEXPECTED_REMOTE_ATTACHMENT :
LOG_UNEXPECTED_LOCAL_ATTACHMENT); LOG_UNEXPECTED_LOCAL_ATTACHMENT,
JSON.stringify(attachment_dict));
}, function (error) { }, function (error) {
if ((error instanceof jIO.util.jIOError) && if ((error instanceof jIO.util.jIOError) &&
(error.status_code === 404)) { (error.status_code === 404)) {
...@@ -14916,13 +14933,19 @@ return new Parser; ...@@ -14916,13 +14933,19 @@ return new Parser;
} }
function waitForOpenIndexedDB(db_name, callback) { function waitForOpenIndexedDB(db_name, callback) {
var request;
function canceller() {
if ((request !== undefined) && (request.result !== undefined)) {
request.result.close();
}
}
function resolver(resolve, reject) { function resolver(resolve, reject) {
// Open DB // // Open DB //
var request = indexedDB.open(db_name); request = indexedDB.open(db_name);
request.onerror = function (error) { request.onerror = function (error) {
if (request.result) { canceller();
request.result.close();
}
if ((error !== undefined) && if ((error !== undefined) &&
(error.target instanceof IDBOpenDBRequest) && (error.target instanceof IDBOpenDBRequest) &&
(error.target.error instanceof DOMError)) { (error.target.error instanceof DOMError)) {
...@@ -14934,17 +14957,16 @@ return new Parser; ...@@ -14934,17 +14957,16 @@ return new Parser;
}; };
request.onabort = function () { request.onabort = function () {
request.result.close(); canceller();
reject("Aborting connection to: " + db_name); reject("Aborting connection to: " + db_name);
}; };
request.ontimeout = function () { request.ontimeout = function () {
request.result.close();
reject("Connection to: " + db_name + " timeout"); reject("Connection to: " + db_name + " timeout");
}; };
request.onblocked = function () { request.onblocked = function () {
request.result.close(); canceller();
reject("Connection to: " + db_name + " was blocked"); reject("Connection to: " + db_name + " was blocked");
}; };
...@@ -14952,26 +14974,32 @@ return new Parser; ...@@ -14952,26 +14974,32 @@ return new Parser;
request.onupgradeneeded = handleUpgradeNeeded; request.onupgradeneeded = handleUpgradeNeeded;
request.onversionchange = function () { request.onversionchange = function () {
request.result.close(); canceller();
reject(db_name + " was upgraded"); reject(db_name + " was upgraded");
}; };
request.onsuccess = function () { request.onsuccess = function () {
var result;
try {
result = callback(request.result);
} catch (error) {
reject(error);
}
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
return callback(request.result); return result;
}) })
.push(function (result) { .push(function (final_result) {
request.result.close(); canceller();
resolve(result); resolve(final_result);
}, function (error) { }, function (error) {
request.result.close(); canceller();
reject(error); reject(error);
}); });
}; };
} }
return new RSVP.Promise(resolver); return new RSVP.Promise(resolver, canceller);
} }
function waitForTransaction(db, stores, flag, callback) { function waitForTransaction(db, stores, flag, callback) {
...@@ -15001,14 +15029,8 @@ return new Parser; ...@@ -15001,14 +15029,8 @@ return new Parser;
reject(error); reject(error);
}); });
}; };
tx.onerror = function (error) { tx.onerror = reject;
canceller(); tx.onabort = reject;
reject(error);
};
tx.onabort = function (evt) {
reject(evt.target);
};
return tx;
} }
return new RSVP.Promise(resolver, canceller); return new RSVP.Promise(resolver, canceller);
} }
......
This diff is collapsed.
This diff is collapsed.
{ {
"name": "jio", "name": "jio",
"version": "v3.37.0", "version": "v3.38.0",
"license": "GPLv3+", "license": "GPLv3+",
"author": "Nexedi SA", "author": "Nexedi SA",
"contributors": [ "contributors": [
......
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