Commit 923a85d2 authored by Bryan Kaperick's avatar Bryan Kaperick

Added revision_history property on historystorage initialization to allow any...

Added revision_history property on historystorage initialization to allow any ids and metadata properties to be set without conflicts 'under the hood'.
parent f9bdfa9b
...@@ -15,13 +15,6 @@ ...@@ -15,13 +15,6 @@
return timestamp + "-" + uuid; return timestamp + "-" + uuid;
} }
function isTimestamp(id) {
//A timestamp is of the form
//"[13 digit number]-[4 numbers/lowercase letters]"
var re = /^[0-9]{13}-[a-z0-9]{4}$/;
return re.test(id);
}
function throwCantFindError(id) { function throwCantFindError(id) {
throw new jIO.util.jIOError( throw new jIO.util.jIOError(
"HistoryStorage: cannot find object '" + id + "'", "HistoryStorage: cannot find object '" + id + "'",
...@@ -44,24 +37,27 @@ ...@@ -44,24 +37,27 @@
*/ */
function HistoryStorage(spec) { function HistoryStorage(spec) {
this._sub_storage = jIO.createJIO(spec.sub_storage); this._sub_storage = jIO.createJIO(spec.sub_storage);
this._include_revisions = spec.include_revisions; if (spec.hasOwnProperty("include_revisions")) {
this._include_revisions = spec.include_revisions;
} else {
this._include_revisions = false;
}
} }
HistoryStorage.prototype.get = function (id_in) { HistoryStorage.prototype.get = function (id_in) {
if (isTimestamp(id_in)) { if (this._include_revisions) {
// Try to treat id_in as a timestamp instead of a name // Try to treat id_in as a timestamp instead of a name
return this._sub_storage.get(id_in) return this._sub_storage.get(id_in)
.push(function (result) { .push(function (result) {
if (result.op === "put") { if (result.op === "put") {
return result.doc; return result.doc;
} }
throwCantFindError(id_in); throwRemovedError(id_in);
}, function (error) { }, function (error) {
if (error.status_code === 404 && if (error.status_code === 404 &&
error instanceof jIO.util.jIOError) { error instanceof jIO.util.jIOError) {
throwRemovedError(id_in); throwCantFindError(id_in);
} }
throw error; throw error;
}); });
...@@ -92,7 +88,7 @@ ...@@ -92,7 +88,7 @@
}; };
return substorage.allDocs(options) return substorage.allDocs(options)
.push(function (results) { .push(function (results) {
if (results.data.rows.length > 0) { if (results.data.total_rows > 0) {
if (results.data.rows[0].value.op === "put") { if (results.data.rows[0].value.op === "put") {
return substorage.get(results.data.rows[0].id) return substorage.get(results.data.rows[0].id)
.push(function (result) { .push(function (result) {
...@@ -107,12 +103,6 @@ ...@@ -107,12 +103,6 @@
HistoryStorage.prototype.put = function (id, data) { HistoryStorage.prototype.put = function (id, data) {
if (isTimestamp(id)) {
throw new jIO.util.jIOError(
"Document cannot have id of the same form as a timestamp",
422
);
}
var timestamp = generateUniqueTimestamp(Date.now()), var timestamp = generateUniqueTimestamp(Date.now()),
metadata = { metadata = {
// XXX: remove this attribute once query can sort_on id // XXX: remove this attribute once query can sort_on id
...@@ -145,7 +135,7 @@ ...@@ -145,7 +135,7 @@
query_doc_id, query_doc_id,
options_remcheck; options_remcheck;
if (isTimestamp(id)) { if (this._include_revisions) {
query_doc_id = new SimpleQuery({ query_doc_id = new SimpleQuery({
operator: "<=", operator: "<=",
key: "timestamp", key: "timestamp",
...@@ -253,7 +243,7 @@ ...@@ -253,7 +243,7 @@
HistoryStorage.prototype.getAttachment = function (id, name) { HistoryStorage.prototype.getAttachment = function (id, name) {
if (isTimestamp(id)) { if (this._include_revisions) {
return this._sub_storage.getAttachment(id, name) return this._sub_storage.getAttachment(id, name)
.push(undefined, function (error) { .push(undefined, function (error) {
if (error.status_code === 404 && if (error.status_code === 404 &&
...@@ -304,7 +294,7 @@ ...@@ -304,7 +294,7 @@
}; };
return substorage.allDocs(options) return substorage.allDocs(options)
.push(function (results) { .push(function (results) {
if (results.data.rows.length > 0) { if (results.data.total_rows > 0) {
if (results.data.rows[0].value.op === "remove" || if (results.data.rows[0].value.op === "remove" ||
results.data.rows[0].value.op === "removeAttachment") { results.data.rows[0].value.op === "removeAttachment") {
throwRemovedError(id); throwRemovedError(id);
...@@ -352,7 +342,7 @@ ...@@ -352,7 +342,7 @@
// Check if query involved _timestamp. // Check if query involved _timestamp.
// If not, use default behavior and only query on latest revisions // If not, use default behavior and only query on latest revisions
rev_query = options.include_revisions, rev_query = this._include_revisions,
doc_id_name, doc_id_name,
timestamp_name; timestamp_name;
...@@ -393,13 +383,16 @@ ...@@ -393,13 +383,16 @@
} }
if (rev_query) { if (rev_query) {
// Only query on documents which are puts are putAttachments
// We only query on versions mapping to puts or putAttachments
results = results.map(function (docum, ind) { results = results.map(function (docum, ind) {
var data_key; var data_key;
if (docum.op === "put") { if (docum.op === "put") {
return docum; return docum;
} }
if (docum.op === "putAttachment") { if (docum.op === "putAttachment") {
// putAttachment document does not contain doc metadata, so we
// add it from the most recent non-removed put on same id
docum.doc = {}; docum.doc = {};
for (i = ind + 1; i < results.length; i += 1) { for (i = ind + 1; i < results.length; i += 1) {
if (results[i].doc_id === docum.doc_id) { if (results[i].doc_id === docum.doc_id) {
...@@ -411,10 +404,9 @@ ...@@ -411,10 +404,9 @@
} }
return docum; return docum;
} }
// If most recent edit on document was a remove before this
// attachment, then don't include attachment in query
if (results[i].doc_id === "remove") { if (results[i].doc_id === "remove") {
//console.log("not returning putAttachment at ",
// docum.timestamp,
// " because it was attached to a removed document");
return false; return false;
} }
} }
...@@ -423,20 +415,26 @@ ...@@ -423,20 +415,26 @@
return false; return false;
}); });
} else { } else {
// Only query on latest revisions of non-removed documents/attachment
// edits
results = results.map(function (docum, ind) { results = results.map(function (docum, ind) {
var data_key; var data_key;
if (docum.op === "put") { if (docum.op === "put") {
// Mark as read and include in query
if (!seen.hasOwnProperty(docum.doc_id)) { if (!seen.hasOwnProperty(docum.doc_id)) {
seen[docum.doc_id] = {}; seen[docum.doc_id] = {};
//console.log("returning put at ", docum.timestamp,
// " because it is most recent edit to " + docum.doc_id);
return docum; return docum;
} }
//console.log("not returning put at ", docum.timestamp,
// " because it was edited later"); } else if (docum.op === "remove" ||
} else if (docum.op === "remove") { docum.op === "removeAttachment") {
// Mark as read but do not include in query
seen[docum.doc_id] = {}; seen[docum.doc_id] = {};
} else if (docum.op === "putAttachment") { } else if (docum.op === "putAttachment") {
// If latest edit, mark as read, add document metadata from most
// recent put, and add to query
if (!seen.hasOwnProperty(docum.doc_id)) { if (!seen.hasOwnProperty(docum.doc_id)) {
seen[docum.doc_id] = {}; seen[docum.doc_id] = {};
docum.doc = {}; docum.doc = {};
...@@ -448,41 +446,37 @@ ...@@ -448,41 +446,37 @@
docum.doc[data_key] = results[i].doc[data_key]; docum.doc[data_key] = results[i].doc[data_key];
} }
} }
/**console.log("returning putAttachment at ",
docum.timestamp,
" because it is most recent edit to attachment " +
docum.name + " of document " + docum.doc_id);
**/
return docum; return docum;
} }
if (results[i].doc_id === "remove") { if (results[i].doc_id === "remove") {
/**console.log("not returning putAttachment at ", // If most recent edit on document was a remove before
docum.timestamp, // this attachment, then don't include attachment in query
" because it was attached to a removed document");
**/
return false; return false;
} }
} }
} }
} }
} else if (docum.op === "removeAttachment") {
seen[docum.doc_id] = {};
} }
return false; return false;
}); });
} }
docs_to_query = results docs_to_query = results
.filter(function (docum) { .filter(function (docum) {
return docum; return docum;
}) })
.map(function (docum) { .map(function (docum) {
// Save timestamp and id information for retrieval at the end of
// buildQuery
docum.doc[timestamp_name] = docum.timestamp; docum.doc[timestamp_name] = docum.timestamp;
docum.doc[doc_id_name] = docum.doc_id; docum.doc[doc_id_name] = docum.doc_id;
return docum.doc; return docum.doc;
}); });
// Return timestamp and id information from query
options.select_list.push(doc_id_name); options.select_list.push(doc_id_name);
options.select_list.push(timestamp_name); options.select_list.push(timestamp_name);
// Sort on timestamp with updated timestamp_name
options.sort_on[options.sort_on.length - 1] = [ options.sort_on[options.sort_on.length - 1] = [
timestamp_name, "descending" timestamp_name, "descending"
]; ];
......
...@@ -48,6 +48,20 @@ ...@@ -48,6 +48,20 @@
} }
} }
}); });
this.history = jIO.createJIO({
type: "history",
include_revisions: true,
sub_storage: {
type: "query",
sub_storage: {
type: "uuid",
sub_storage: {
type: "indexeddb",
database: dbname
}
}
}
});
this.not_history = jIO.createJIO({ this.not_history = jIO.createJIO({
type: "query", type: "query",
sub_storage: { sub_storage: {
...@@ -66,6 +80,7 @@ ...@@ -66,6 +80,7 @@
stop(); stop();
expect(10); expect(10);
var jio = this.jio, var jio = this.jio,
history = this.history,
not_history = this.not_history, not_history = this.not_history,
timestamps, timestamps,
blob2 = this.blob2, blob2 = this.blob2,
...@@ -120,7 +135,7 @@ ...@@ -120,7 +135,7 @@
blob2, blob2,
"Return the attachment information with getAttachment" "Return the attachment information with getAttachment"
); );
return jio.getAttachment( return history.getAttachment(
timestamps[3], timestamps[3],
"attacheddata" "attacheddata"
); );
...@@ -131,7 +146,7 @@ ...@@ -131,7 +146,7 @@
"Return the attachment information with getAttachment for " + "Return the attachment information with getAttachment for " +
"current revision" "current revision"
); );
return jio.getAttachment( return history.getAttachment(
timestamps[2], timestamps[2],
"attacheddata" "attacheddata"
); );
...@@ -313,7 +328,7 @@ ...@@ -313,7 +328,7 @@
return jio.allDocs(); return jio.allDocs();
}) })
.push(function (results) { .push(function (results) {
equal(results.data.rows.length, equal(results.data.total_rows,
2, 2,
"Two documents in accessible storage"); "Two documents in accessible storage");
return jio.get(results.data.rows[1].id); return jio.get(results.data.rows[1].id);
...@@ -373,6 +388,7 @@ ...@@ -373,6 +388,7 @@
stop(); stop();
expect(8); expect(8);
var jio = this.jio, var jio = this.jio,
history = this.history,
not_history = this.not_history, not_history = this.not_history,
blob1 = new Blob(['a']), blob1 = new Blob(['a']),
blob11 = new Blob(['ab']), blob11 = new Blob(['ab']),
...@@ -430,12 +446,12 @@ ...@@ -430,12 +446,12 @@
}, },
"Current state of document is correct"); "Current state of document is correct");
return jio.allAttachments(timestamps[0]); return history.allAttachments(timestamps[0]);
}) })
.push(function (results) { .push(function (results) {
deepEqual(results, {}, "First version of document has 0 attachments"); deepEqual(results, {}, "First version of document has 0 attachments");
return jio.allAttachments(timestamps[1]); return history.allAttachments(timestamps[1]);
}) })
.push(function (results) { .push(function (results) {
deepEqual(results, { deepEqual(results, {
...@@ -443,13 +459,13 @@ ...@@ -443,13 +459,13 @@
data2: blob2 data2: blob2
}, "Both attachments are included in allAttachments"); }, "Both attachments are included in allAttachments");
return jio.allAttachments(timestamps[2]); return history.allAttachments(timestamps[2]);
}) })
.push(function (results) { .push(function (results) {
deepEqual(results, { deepEqual(results, {
data: blob1 data: blob1
}, "Removed attachment does not show up in allAttachments"); }, "Removed attachment does not show up in allAttachments");
return jio.allAttachments(timestamps[3]); return history.allAttachments(timestamps[3]);
}) })
.push(function () { .push(function () {
ok(false, "This query should have thrown a 404 error"); ok(false, "This query should have thrown a 404 error");
...@@ -465,7 +481,7 @@ ...@@ -465,7 +481,7 @@
"Error is handled by Historystorage."); "Error is handled by Historystorage.");
}) })
.push(function () { .push(function () {
return jio.allAttachments(timestamps[4]); return history.allAttachments(timestamps[4]);
}) })
.push(function (results) { .push(function (results) {
deepEqual(results, { deepEqual(results, {
...@@ -501,6 +517,20 @@ ...@@ -501,6 +517,20 @@
} }
} }
}); });
this.history = jIO.createJIO({
type: "history",
include_revisions: true,
sub_storage: {
type: "query",
sub_storage: {
type: "uuid",
sub_storage: {
type: "indexeddb",
database: dbname
}
}
}
});
this.not_history = jIO.createJIO({ this.not_history = jIO.createJIO({
type: "query", type: "query",
sub_storage: { sub_storage: {
...@@ -519,17 +549,60 @@ ...@@ -519,17 +549,60 @@
stop(); stop();
expect(2); expect(2);
var jio = this.jio, var jio = this.jio,
BADINPUT_ERRCODE = 422; history = this.history,
timestamp;
jio.put("doc", {title: "foo"})
.push(function () {
return history.allDocs();
})
.push(function (res) {
timestamp = res.data.rows[0].timestamp;
return history.put(timestamp, {key: "val"});
})
.push(function () {
return jio.get("doc");
})
.push(function (result) {
deepEqual(result, {
title: "foo"
}, "Saving document with timestamp id does not cause issues (1)");
return history.get(timestamp);
})
.push(function (result) {
deepEqual(result, {
title: "foo"
}, "Saving document with timestamp id does not cause issues (2)");
return history.get(timestamp);
})
.fail(function (error) {
//console.log(error);
ok(false, error);
})
.always(function () {start(); });
});
jio.put("1234567891123-ab7d", {}) test("Getting a non-existent document",
function () {
stop();
expect(3);
var jio = this.jio;
jio.put("not_doc", {})
.push(function () {
return jio.get("doc");
})
.push(function () { .push(function () {
ok(false, "This statement should not be reached"); ok(false, "This statement should not be reached");
}, function (error) { }, function (error) {
//console.log(error);
ok(error instanceof jIO.util.jIOError, "Correct type of error"); ok(error instanceof jIO.util.jIOError, "Correct type of error");
deepEqual(error.status_code, deepEqual(error.status_code,
BADINPUT_ERRCODE, 404,
"Can't save a document with a timestamp-formatted id" "Correct status code for getting a non-existent document"
); );
deepEqual(error.message,
"HistoryStorage: cannot find object 'doc'",
"Error is handled by history storage before reaching console");
}) })
.fail(function (error) { .fail(function (error) {
//console.log(error); //console.log(error);
...@@ -538,11 +611,13 @@ ...@@ -538,11 +611,13 @@
.always(function () {start(); }); .always(function () {start(); });
}); });
test("Getting a non-existent document", test("Getting a document with timestamp when include_revisions is false",
function () { function () {
stop(); stop();
expect(3); expect(9);
var jio = this.jio; var jio = this.jio,
history = this.history,
timestamp;
jio.put("not_doc", {}) jio.put("not_doc", {})
.push(function () { .push(function () {
return jio.get("doc"); return jio.get("doc");
...@@ -560,6 +635,41 @@ ...@@ -560,6 +635,41 @@
"HistoryStorage: cannot find object 'doc'", "HistoryStorage: cannot find object 'doc'",
"Error is handled by history storage before reaching console"); "Error is handled by history storage before reaching console");
}) })
.push(function () {
return history.allDocs();
})
.push(function (results) {
timestamp = results.data.rows[0].timestamp;
return jio.get(timestamp);
})
.push(function () {
ok(false, "This statement should not be reached");
}, function (error) {
ok(error instanceof jIO.util.jIOError, "Correct type of error");
deepEqual(error.status_code,
404,
"Correct status code for getting a non-existent document"
);
deepEqual(error.message,
"HistoryStorage: cannot find object '" + timestamp + "'",
"Error is handled by history storage before reaching console");
})
.push(function () {
return history.get("doc");
})
.push(function () {
ok(false, "This statement should not be reached");
}, function (error) {
//console.log(error);
ok(error instanceof jIO.util.jIOError, "Correct type of error");
deepEqual(error.status_code,
404,
"Correct status code for getting a non-existent document"
);
deepEqual(error.message,
"HistoryStorage: cannot find object 'doc'",
"Error is handled by history storage before reaching console");
})
.fail(function (error) { .fail(function (error) {
//console.log(error); //console.log(error);
ok(false, error); ok(false, error);
...@@ -570,8 +680,9 @@ ...@@ -570,8 +680,9 @@
test("Creating a document with put and retrieving it with get", test("Creating a document with put and retrieving it with get",
function () { function () {
stop(); stop();
expect(7); expect(5);
var jio = this.jio, var jio = this.jio,
history = this.history,
not_history = this.not_history, not_history = this.not_history,
timestamps; timestamps;
jio.put("doc", {title: "version0"}) jio.put("doc", {title: "version0"})
...@@ -590,7 +701,7 @@ ...@@ -590,7 +701,7 @@
1, 1,
"One revision is saved in storage" "One revision is saved in storage"
); );
return jio.get(timestamps[0]); return history.get(timestamps[0]);
}) })
.push(function (result) { .push(function (result) {
deepEqual(result, { deepEqual(result, {
...@@ -623,18 +734,6 @@ ...@@ -623,18 +734,6 @@
"Can't access non-existent document" "Can't access non-existent document"
); );
}) })
.push(function () {
return jio.get("1234567891123-abcd");
})
.push(function () {
ok(false, "Trying to get a non-existent id should have raised 404");
}, function (error) {
ok(error instanceof jIO.util.jIOError, "Correct type of error");
deepEqual(error.status_code,
404,
"Can't access document by getting with non-existent id"
);
})
.fail(function (error) { .fail(function (error) {
//console.log(error); //console.log(error);
ok(false, error); ok(false, error);
...@@ -647,6 +746,7 @@ ...@@ -647,6 +746,7 @@
stop(); stop();
expect(7); expect(7);
var jio = this.jio, var jio = this.jio,
history = this.history,
not_history = this.not_history, not_history = this.not_history,
timestamps; timestamps;
...@@ -682,7 +782,7 @@ ...@@ -682,7 +782,7 @@
title: "t3", title: "t3",
subtitle: "s3" subtitle: "s3"
}, "Get returns latest revision"); }, "Get returns latest revision");
return jio.get(timestamps[0]); return history.get(timestamps[0]);
}, function (err) { }, function (err) {
ok(false, err); ok(false, err);
}) })
...@@ -691,14 +791,14 @@ ...@@ -691,14 +791,14 @@
title: "t0", title: "t0",
subtitle: "s0" subtitle: "s0"
}, "Get returns first version"); }, "Get returns first version");
return jio.get(timestamps[1]); return history.get(timestamps[1]);
}) })
.push(function (result) { .push(function (result) {
deepEqual(result, { deepEqual(result, {
title: "t1", title: "t1",
subtitle: "s1" subtitle: "s1"
}, "Get returns second version"); }, "Get returns second version");
return jio.get(timestamps[2]); return history.get(timestamps[2]);
}, function (err) { }, function (err) {
ok(false, err); ok(false, err);
}) })
...@@ -707,20 +807,20 @@ ...@@ -707,20 +807,20 @@
title: "t2", title: "t2",
subtitle: "s2" subtitle: "s2"
}, "Get returns third version"); }, "Get returns third version");
return jio.get(timestamps[3]); return history.get(timestamps[3]);
}, function (err) { }, function (err) {
ok(false, err); ok(false, err);
}) })
.push(function () { .push(function () {
ok(false, "This should have thrown a 404 error"); ok(false, "This should have thrown a 404 error");
return jio.get(timestamps[4]); return history.get(timestamps[4]);
}, },
function (error) { function (error) {
ok(error instanceof jIO.util.jIOError, "Correct type of error"); ok(error instanceof jIO.util.jIOError, "Correct type of error");
deepEqual(error.status_code, deepEqual(error.status_code,
404, 404,
"Error if you try to go back more revisions than what exists"); "Error if you try to go back more revisions than what exists");
return jio.get(timestamps[4]); return history.get(timestamps[4]);
}) })
.push(function (result) { .push(function (result) {
deepEqual(result, { deepEqual(result, {
...@@ -767,7 +867,7 @@ ...@@ -767,7 +867,7 @@
}); });
}) })
.push(function (results) { .push(function (results) {
equal(results.data.rows.length, equal(results.data.total_rows,
9, 9,
"All nine versions exist in storage"); "All nine versions exist in storage");
return not_history.get(results.data.rows[0].id); return not_history.get(results.data.rows[0].id);
...@@ -801,7 +901,7 @@ ...@@ -801,7 +901,7 @@
}); });
}) })
.push(function (results) { .push(function (results) {
equal(results.data.rows.length, equal(results.data.total_rows,
10, 10,
"Remove operation is recorded"); "Remove operation is recorded");
return not_history.get(results.data.rows[0].id); return not_history.get(results.data.rows[0].id);
...@@ -841,6 +941,20 @@ ...@@ -841,6 +941,20 @@
} }
} }
}); });
this.history = jIO.createJIO({
type: "history",
include_revisions: true,
sub_storage: {
type: "query",
sub_storage: {
type: "uuid",
sub_storage: {
type: "indexeddb",
database: dbname
}
}
}
});
this.not_history = jIO.createJIO({ this.not_history = jIO.createJIO({
type: "query", type: "query",
sub_storage: { sub_storage: {
...@@ -889,7 +1003,7 @@ ...@@ -889,7 +1003,7 @@
return results[0]; return results[0];
}) })
.push(function (results) { .push(function (results) {
equal(results.data.rows.length, equal(results.data.total_rows,
1, 1,
"Exactly one result returned"); "Exactly one result returned");
deepEqual(results.data.rows[0], { deepEqual(results.data.rows[0], {
...@@ -903,7 +1017,7 @@ ...@@ -903,7 +1017,7 @@
return not_history.allDocs(); return not_history.allDocs();
}) })
.push(function (results) { .push(function (results) {
equal(results.data.rows.length, equal(results.data.total_rows,
1, 1,
"Exactly one result returned"); "Exactly one result returned");
return not_history.get(results.data.rows[0].id); return not_history.get(results.data.rows[0].id);
...@@ -989,6 +1103,7 @@ ...@@ -989,6 +1103,7 @@
stop(); stop();
expect(10); expect(10);
var jio = this.jio, var jio = this.jio,
history = this.history,
not_history = this.not_history, not_history = this.not_history,
timestamps; timestamps;
jio.put("doc", { jio.put("doc", {
...@@ -1055,7 +1170,7 @@ ...@@ -1055,7 +1170,7 @@
return results[0]; return results[0];
}) })
.push(function (results) { .push(function (results) {
equal(results.data.rows.length, equal(results.data.total_rows,
1, 1,
"Exactly one result returned"); "Exactly one result returned");
deepEqual(results.data.rows[0], { deepEqual(results.data.rows[0], {
...@@ -1071,14 +1186,13 @@ ...@@ -1071,14 +1186,13 @@
); );
}) })
.push(function () { .push(function () {
return jio.allDocs({ return history.allDocs({
query: "", query: "",
select_list: ["title", "subtitle"], select_list: ["title", "subtitle"]
include_revisions: true
}); });
}) })
.push(function (results) { .push(function (results) {
equal(results.data.rows.length, equal(results.data.total_rows,
3, 3,
"Querying with include_revisions retrieves all versions"); "Querying with include_revisions retrieves all versions");
deepEqual(results.data.rows, [ deepEqual(results.data.rows, [
...@@ -1214,7 +1328,7 @@ ...@@ -1214,7 +1328,7 @@
return jio.allDocs({sort_on: [["timestamp", "descending"]]}); return jio.allDocs({sort_on: [["timestamp", "descending"]]});
}) })
.push(function (results) { .push(function (results) {
equal(results.data.rows.length, equal(results.data.total_rows,
2, 2,
"Only two non-removed unique documents exist." "Only two non-removed unique documents exist."
); );
...@@ -1308,7 +1422,7 @@ ...@@ -1308,7 +1422,7 @@
}); });
}) })
.push(function (results) { .push(function (results) {
equal(results.data.rows.length, 3); equal(results.data.total_rows, 3);
deepEqual(results.data.rows, [ deepEqual(results.data.rows, [
{ {
doc: {}, doc: {},
...@@ -1347,6 +1461,7 @@ ...@@ -1347,6 +1461,7 @@
stop(); stop();
expect(3); expect(3);
var jio = this.jio, var jio = this.jio,
history = this.history,
not_history = this.not_history, not_history = this.not_history,
timestamps, timestamps,
docs = [ docs = [
...@@ -1540,12 +1655,11 @@ ...@@ -1540,12 +1655,11 @@
], "All versions of documents are stored correctly"); ], "All versions of documents are stored correctly");
}) })
.push(function () { .push(function () {
return jio.allDocs({ return history.allDocs({
query: "NOT (date: >= 2 AND date: <= 3)", query: "NOT (date: >= 2 AND date: <= 3)",
select_list: ["date", "non-existent-key", "type", "title"], select_list: ["date", "non-existent-key", "type", "title"],
sort_on: [["date", "descending"] sort_on: [["date", "descending"]
], ]
include_revisions: true
}); });
}) })
.push(function (results) { .push(function (results) {
...@@ -1636,6 +1750,7 @@ ...@@ -1636,6 +1750,7 @@
this.blob2 = new Blob(['b']); this.blob2 = new Blob(['b']);
this.blob3 = new Blob(['ccc']); this.blob3 = new Blob(['ccc']);
this.other_blob = new Blob(['1']); this.other_blob = new Blob(['1']);
this.jio = jIO.createJIO({ this.jio = jIO.createJIO({
type: "history", type: "history",
sub_storage: { sub_storage: {
...@@ -1649,6 +1764,20 @@ ...@@ -1649,6 +1764,20 @@
} }
} }
}); });
this.history = jIO.createJIO({
type: "history",
include_revisions: true,
sub_storage: {
type: "query",
sub_storage: {
type: "uuid",
sub_storage: {
type: "indexeddb",
database: dbname
}
}
}
});
this.not_history = jIO.createJIO({ this.not_history = jIO.createJIO({
type: "query", type: "query",
sub_storage: { sub_storage: {
...@@ -1667,6 +1796,7 @@ ...@@ -1667,6 +1796,7 @@
stop(); stop();
expect(1); expect(1);
var jio = this.jio, var jio = this.jio,
history = this.history,
not_history = this.not_history, not_history = this.not_history,
timestamps, timestamps,
blobs1 = [ blobs1 = [
...@@ -1716,9 +1846,8 @@ ...@@ -1716,9 +1846,8 @@
}) })
.push(function () { .push(function () {
return jio.allDocs({ return history.allDocs({
select_list: ["title"], select_list: ["title"]
include_revisions: true
}); });
}) })
.push(function (results) { .push(function (results) {
...@@ -1824,6 +1953,7 @@ ...@@ -1824,6 +1953,7 @@
expect(1); expect(1);
var jio = this.jio, var jio = this.jio,
not_history = this.not_history, not_history = this.not_history,
history = this.history,
timestamps, timestamps,
blobs1 = [ blobs1 = [
new Blob(['a']), new Blob(['a']),
...@@ -1859,9 +1989,8 @@ ...@@ -1859,9 +1989,8 @@
}) })
.push(function () { .push(function () {
return jio.allDocs({ return history.allDocs({
select_list: ["title"], select_list: ["title"]
include_revisions: true
}); });
}) })
.push(function (results) { .push(function (results) {
...@@ -1913,6 +2042,7 @@ ...@@ -1913,6 +2042,7 @@
expect(2); expect(2);
var jio = this.jio, var jio = this.jio,
not_history = this.not_history, not_history = this.not_history,
history = this.history,
timestamps, timestamps,
blobs1 = [ blobs1 = [
new Blob(['a']), new Blob(['a']),
...@@ -1948,8 +2078,7 @@ ...@@ -1948,8 +2078,7 @@
}) })
.push(function () { .push(function () {
return jio.allDocs({ return jio.allDocs({
select_list: ["title"], select_list: ["title"]
include_revisions: false
}); });
}) })
.push(function (results) { .push(function (results) {
...@@ -1970,9 +2099,8 @@ ...@@ -1970,9 +2099,8 @@
"allDocs with include_revisions false should return all revisions"); "allDocs with include_revisions false should return all revisions");
}) })
.push(function () { .push(function () {
return jio.allDocs({ return history.allDocs({
select_list: ["title"], select_list: ["title"]
include_revisions: true
}); });
}) })
.push(function (results) { .push(function (results) {
......
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