Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
jio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Bryan Kaperick
jio
Commits
30b0e964
Commit
30b0e964
authored
Jun 05, 2018
by
Bryan Kaperick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revision history tests are passing as expected now.
parent
adb69072
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
131 additions
and
100 deletions
+131
-100
src/jio.storage/bryanstorage.js
src/jio.storage/bryanstorage.js
+10
-24
test/jio.storage/bryanstorage.tests.js
test/jio.storage/bryanstorage.tests.js
+121
-76
No files found.
src/jio.storage/bryanstorage.js
View file @
30b0e964
...
...
@@ -39,7 +39,7 @@
// Prepare to post the current doc as a deprecated version
previous_data
=
latest_data
;
previous_data
.
_deprecated
=
true
;
previous_data
.
_deprecated
=
"
true
"
;
previous_data
.
_doc_id
=
id
;
// Get most recent deprecated version's _revision attribute
...
...
@@ -53,9 +53,9 @@
})
.
push
(
function
(
query_results
)
{
if
(
query_results
.
length
>
0
)
{
var
doc_id
=
query_results
[
0
]
;
return
this
.
_sub_
storage
.
get
(
doc_id
);
if
(
query_results
.
data
.
rows
.
length
>
0
)
{
var
doc_id
=
query_results
.
data
.
rows
[
0
].
id
;
return
sub
storage
.
get
(
doc_id
);
}
throw
new
jIO
.
util
.
jIOError
(
"
bryanstorage: query returned no results.'
"
,
...
...
@@ -143,30 +143,16 @@
BryanStorage
.
prototype
.
hasCapacity
=
function
()
{
return
this
.
_sub_storage
.
hasCapacity
.
apply
(
this
.
_sub_storage
,
arguments
);
};
/**
BryanStorage.prototype.allDocs = function (options) {
if (options === undefined) {
options = {};
}
console.log("options", options);
BryanStorage
.
prototype
.
buildQuery
=
function
(
options
)
{
if
(
options
===
undefined
)
{
options
=
{
query
:
""
};
}
options.query = '(' + options.query + ') AND NOT (_deprecated = true)';
console.log("query string: ", options.query);
return this._sub_storage.allDocs.apply(this._sub_storage, options);
//return this._sub_storage.buildQuery.apply(this._sub_storage, options);
};
**/
BryanStorage
.
prototype
.
buildQuery
=
function
()
{
/**
if (options === undefined) {
options = {};
if
(
options
.
query
!==
""
)
{
options
.
query
=
"
(
"
+
options
.
query
+
"
) AND
"
;
}
options.query = '(' + options.query + ') AND NOT (_deprecated = true)';
**/
console
.
log
(
"
options
"
,
arguments
);
return
this
.
_sub_storage
.
buildQuery
.
apply
(
this
.
_sub_storage
,
arguments
);
options
.
query
=
options
.
query
+
'
NOT (_deprecated: "true")
'
;
return
this
.
_sub_storage
.
buildQuery
(
options
);
};
jIO
.
addStorage
(
'
bryan
'
,
BryanStorage
);
...
...
test/jio.storage/bryanstorage.tests.js
View file @
30b0e964
...
...
@@ -30,21 +30,43 @@
type: "memory"
}
}
});
}),
not_bryan = jIO.createJIO({
type: "query",
sub_storage: {
type: "uuid",
sub_storage: {
type: "memory"
}
}
});
jio.put("bar", {"title": "foo"});
jio.put("bar", {"title": "foo
0
"});
RSVP.all([
jio.put("bar", {"title2": "foo2"}),
jio.put("bar", {"title3": "foo3"})
]
);
//.push(function () {return jio.get("bar"); })
jio.get("bar")
.push(function (result) {equal(result._revision, 3, "parallel exec"); })
jio.put("bar", {"title": "foo1"}),
jio.put("bar", {"title": "foo2"}),
jio.put("bar", {"title": "foo3"}),
jio.put("bar", {"title": "foo4"})
])
.push(function () {return jio.get("bar"); })
.push(function (result) {
deepEqual(result, {
"title": "foo4"
});
})
.push(function () {return not_bryan.allDocs({
query: "_revision: 0"
});
})
.push(function (results) {
equal(results.data.rows.length,
1,
"Only one document with _revision = 0");
})
.fail(function (error) {ok(false, error); })
.always(function () {start(); });
});
**/
**/
/////////////////////////////////////////////////////////////////
...
...
@@ -53,8 +75,8 @@
module
(
"
bryanStorage.revision_history
"
);
test
(
"
put and get the correct version
"
,
function
()
{
stop
();
expect
(
4
);
var
dbname
=
"
fresh
db0
"
,
expect
(
7
);
var
dbname
=
"
rev_hist_
db0
"
,
jio
=
jIO
.
createJIO
({
type
:
"
bryan
"
,
sub_storage
:
{
...
...
@@ -76,20 +98,22 @@
database
:
dbname
}
}
});
}),
query_input
=
{
query
:
'
NOT (_deprecated: "true")
'
,
sort_on
:
[[
'
_revision
'
,
'
descending
'
]]
},
query_input2
=
{
query
:
'
title: "rev1"
'
,
sort_on
:
[[
'
_revision
'
,
'
descending
'
]]
};
jio
.
put
(
"
doc1
"
,
{
"
title
"
:
"
rev0
"
,
"
subtitle
"
:
"
subrev0
"
})
.
push
(
function
()
{
return
jio
.
get
(
"
doc1
"
);
})
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
"
title
"
:
"
rev0
"
,
"
subtitle
"
:
"
subrev0
"
},
"
Retrieve first edition of document correctly
"
);
})
.
push
(
function
()
{
return
jio
.
put
(
"
doc1
"
,
{
"
title
"
:
"
rev1
"
,
...
...
@@ -103,60 +127,66 @@
});
})
.
push
(
function
()
{
return
jio
.
get
(
"
doc1
"
);
return
jio
.
put
(
"
doc1
"
,
{
"
title
"
:
"
rev3
"
,
"
subtitle
"
:
"
subrev3
"
});
})
.
push
(
function
()
{
return
jio
.
get
(
"
doc1
"
);
})
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
"
title
"
:
"
rev
2
"
,
"
subtitle
"
:
"
subrev
2
"
},
"
Retrieve
second
edition of document correctly
"
);
"
title
"
:
"
rev
3
"
,
"
subtitle
"
:
"
subrev
3
"
},
"
Retrieve
first
edition of document correctly
"
);
})
.
push
(
function
()
{
var
options
=
{
query
:
"
title: rev0
"
};
return
jio
.
allDocs
(
options
);
return
not_bryan
.
allDocs
(
query_input
);
})
.
push
(
function
(
results
)
{
console
.
log
(
"
query results:
"
,
results
);
equal
(
results
.
data
.
rows
.
length
,
1
,
"
Query only returns latest version
"
);
if
(
results
.
data
.
rows
.
length
>
0
)
{
return
jio
.
get
(
results
.
data
.
rows
[
0
].
id
);
}
equal
(
results
.
data
.
rows
.
length
,
1
,
"
Only 1 version isn't _deprecated
"
);
return
jio
.
get
(
results
.
data
.
rows
[
0
].
id
);
})
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
"
title
"
:
"
rev
2
"
,
"
subtitle
"
:
"
subrev
2
"
},
"
Retrieve
queried document correctly
"
);
"
title
"
:
"
rev
3
"
,
"
subtitle
"
:
"
subrev
3
"
},
"
Retrieve
most recent edition by querying NOT _deprecated
"
);
})
// When not_bryan queries the storage, all documents are returned.
.
push
(
function
()
{
var
options
=
{
query
:
""
,
sort_on
:
[[
"
_revision
"
,
"
ascending
"
]]
};
return
jio
.
allDocs
(
options
);
return
not_bryan
.
allDocs
(
query_input2
);
})
.
push
(
function
(
results
)
{
equal
(
results
.
length
,
2
,
"
should get all 2 revisions.
"
);
if
(
results
.
length
>
0
)
{
return
not_bryan
.
get
(
results
[
0
].
id
);
}
equal
(
results
.
data
.
rows
.
length
,
1
,
"
Only one version is titled 'rev1'
"
);
return
jio
.
get
(
results
.
data
.
rows
[
0
].
id
);
})
.
push
(
function
(
result
s
)
{
deepEqual
(
result
s
,
{
"
title
"
:
"
rev
0
"
,
"
subtitle
"
:
"
subrev
0
"
,
"
_d
oc_id
"
:
"
doc1
"
,
"
_revision
"
:
0
,
"
_d
eprecated
"
:
true
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
"
title
"
:
"
rev
1
"
,
"
subtitle
"
:
"
subrev
1
"
,
"
_d
eprecated
"
:
"
true
"
,
"
_revision
"
:
1
,
"
_d
oc_id
"
:
"
doc1
"
},
"
Get the earliest copy of the doc with all metadata.
"
);
"
Retrieve 1st edit by querying for title: 'rev1' with other storage
"
);
})
.
push
(
function
()
{
return
jio
.
allDocs
({
query
:
''
});
})
.
push
(
function
(
results
)
{
equal
(
results
.
data
.
rows
.
length
,
1
,
"
bryanstorage only sees latest version
"
);
return
jio
.
get
(
results
.
data
.
rows
[
0
].
id
);
})
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
"
title
"
:
"
rev3
"
,
"
subtitle
"
:
"
subrev3
"
},
"
Retrieve latest version correctly with bryanstorage
"
);
})
.
fail
(
function
(
error
)
{
console
.
log
(
error
);
//
console.log(error);
ok
(
false
,
error
);
})
.
always
(
function
()
{
...
...
@@ -164,25 +194,35 @@
});
});
/////////////////////////////////////////////////////////////////
// bryanStorage.revision_history_multiple_edits
/////////////////////////////////////////////////////////////////
module
(
"
bryanStorage.revision_history_multiple_edits
"
);
test
(
"
modify first version but save both
"
,
function
()
{
stop
();
expect
(
7
);
var
jio
=
jIO
.
createJIO
({
expect
(
11
);
var
dbname
=
"
testdb20
"
,
jio
=
jIO
.
createJIO
({
type
:
"
bryan
"
,
sub_storage
:
{
type
:
"
uuid
"
,
sub_storage
:
{
type
:
"
indexeddb
"
,
database
:
"
testdb1
"
database
:
dbname
}
}
}),
not_bryan
=
jIO
.
createJIO
({
type
:
"
uuid
"
,
type
:
"
query
"
,
sub_storage
:
{
type
:
"
indexeddb
"
,
database
:
"
testdb1
"
type
:
"
uuid
"
,
sub_storage
:
{
type
:
"
indexeddb
"
,
database
:
dbname
}
}
});
jio
.
put
(
"
main_doc
"
,
{
...
...
@@ -239,8 +279,9 @@
});
})
.
push
(
function
(
result
)
{
//console.log(result);
equal
(
result
.
length
,
2
,
"
Empty query returns only non-deprecated docs
"
);
equal
(
result
.
data
.
rows
.
length
,
2
,
"
Empty query returns only non-deprecated docs
"
);
})
.
push
(
function
()
{
return
jio
.
allDocs
({
...
...
@@ -248,16 +289,18 @@
});
})
.
push
(
function
(
result
)
{
//console.log("res:", result);
if
(
result
.
length
>
0
)
{
return
jio
.
get
(
result
[
0
].
id
);
equal
(
result
.
data
.
rows
.
length
,
1
,
"
No deprecated results are returned.
"
);
if
(
result
.
data
.
rows
.
length
>
0
)
{
return
jio
.
get
(
result
.
data
.
rows
[
0
].
id
);
}
})
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
"
attr
"
:
"
version1
"
,
"
subattr
"
:
"
subversion1
"
},
"
Retrieve other document correctly
"
);
},
"
Only get most recent edit
"
);
})
.
push
(
function
()
{
return
jio
.
allDocs
({
...
...
@@ -265,7 +308,7 @@
});
})
.
push
(
function
(
result
)
{
equal
(
result
.
length
,
0
,
"
Correct number of results returned
"
);
equal
(
result
.
data
.
rows
.
length
,
0
,
"
Correct number of results returned
"
);
})
.
push
(
function
()
{
return
jio
.
allDocs
({
...
...
@@ -273,7 +316,7 @@
});
})
.
push
(
function
(
result
)
{
equal
(
result
.
length
,
0
,
"
Correct number of results returned
"
);
equal
(
result
.
data
.
rows
.
length
,
0
,
"
Correct number of results returned
"
);
})
.
push
(
function
()
{
return
jio
.
allDocs
({
...
...
@@ -281,7 +324,7 @@
});
})
.
push
(
function
(
result
)
{
equal
(
result
.
length
,
2
,
"
Correct number of results returned
"
);
equal
(
result
.
data
.
rows
.
length
,
2
,
"
Correct number of results returned
"
);
})
// When not_bryan queries the storage, all documents are returned.
...
...
@@ -293,8 +336,10 @@
return
not_bryan
.
allDocs
(
options
);
})
.
push
(
function
(
results
)
{
equal
(
results
.
length
,
3
,
"
should get all 3 deprecated versions.
"
);
return
not_bryan
.
get
(
results
[
0
].
id
);
equal
(
results
.
data
.
rows
.
length
,
3
,
"
should get all 3 deprecated versions.
"
);
return
not_bryan
.
get
(
results
.
data
.
rows
[
0
].
id
);
})
.
push
(
function
(
results
)
{
deepEqual
(
results
,
{
...
...
@@ -302,7 +347,7 @@
"
subtitle
"
:
"
subrev0
"
,
"
_doc_id
"
:
"
main_doc
"
,
"
_revision
"
:
0
,
"
_deprecated
"
:
true
"
_deprecated
"
:
"
true
"
},
"
Get the earliest copy of the doc with all metadata.
"
);
})
...
...
@@ -316,7 +361,7 @@
return
not_bryan
.
allDocs
(
options
);
})
.
push
(
function
(
results
)
{
return
not_bryan
.
get
(
results
[
1
].
id
);
return
not_bryan
.
get
(
results
.
data
.
rows
[
1
].
id
);
})
.
push
(
function
(
results
)
{
deepEqual
(
results
,
{
...
...
@@ -324,7 +369,7 @@
"
subtitle
"
:
"
subrev1
"
,
"
_doc_id
"
:
"
main_doc
"
,
"
_revision
"
:
1
,
"
_deprecated
"
:
true
"
_deprecated
"
:
"
true
"
},
"
Get the earliest copy of the doc with all metadata.
"
);
})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment