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 @@
...
@@ -39,7 +39,7 @@
// Prepare to post the current doc as a deprecated version
// Prepare to post the current doc as a deprecated version
previous_data
=
latest_data
;
previous_data
=
latest_data
;
previous_data
.
_deprecated
=
true
;
previous_data
.
_deprecated
=
"
true
"
;
previous_data
.
_doc_id
=
id
;
previous_data
.
_doc_id
=
id
;
// Get most recent deprecated version's _revision attribute
// Get most recent deprecated version's _revision attribute
...
@@ -53,9 +53,9 @@
...
@@ -53,9 +53,9 @@
})
})
.
push
(
function
(
query_results
)
{
.
push
(
function
(
query_results
)
{
if
(
query_results
.
length
>
0
)
{
if
(
query_results
.
data
.
rows
.
length
>
0
)
{
var
doc_id
=
query_results
[
0
]
;
var
doc_id
=
query_results
.
data
.
rows
[
0
].
id
;
return
this
.
_sub_
storage
.
get
(
doc_id
);
return
sub
storage
.
get
(
doc_id
);
}
}
throw
new
jIO
.
util
.
jIOError
(
throw
new
jIO
.
util
.
jIOError
(
"
bryanstorage: query returned no results.'
"
,
"
bryanstorage: query returned no results.'
"
,
...
@@ -143,30 +143,16 @@
...
@@ -143,30 +143,16 @@
BryanStorage
.
prototype
.
hasCapacity
=
function
()
{
BryanStorage
.
prototype
.
hasCapacity
=
function
()
{
return
this
.
_sub_storage
.
hasCapacity
.
apply
(
this
.
_sub_storage
,
arguments
);
return
this
.
_sub_storage
.
hasCapacity
.
apply
(
this
.
_sub_storage
,
arguments
);
};
};
/**
BryanStorage.prototype.allDocs = function (options) {
BryanStorage
.
prototype
.
buildQuery
=
function
(
options
)
{
if (options === undefined) {
options = {};
}
console.log("options", options);
if
(
options
===
undefined
)
{
if
(
options
===
undefined
)
{
options
=
{
query
:
""
};
options
=
{
query
:
""
};
}
}
options.query = '(' + options.query + ') AND NOT (_deprecated = true)';
if
(
options
.
query
!==
""
)
{
console.log("query string: ", options.query);
options
.
query
=
"
(
"
+
options
.
query
+
"
) AND
"
;
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 = {};
}
}
options.query = '(' + options.query + ') AND NOT (_deprecated = true)';
options
.
query
=
options
.
query
+
'
NOT (_deprecated: "true")
'
;
**/
return
this
.
_sub_storage
.
buildQuery
(
options
);
console
.
log
(
"
options
"
,
arguments
);
return
this
.
_sub_storage
.
buildQuery
.
apply
(
this
.
_sub_storage
,
arguments
);
};
};
jIO
.
addStorage
(
'
bryan
'
,
BryanStorage
);
jIO
.
addStorage
(
'
bryan
'
,
BryanStorage
);
...
...
test/jio.storage/bryanstorage.tests.js
View file @
30b0e964
...
@@ -30,21 +30,43 @@
...
@@ -30,21 +30,43 @@
type: "memory"
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([
RSVP.all([
jio.put("bar", {"title2": "foo2"}),
jio.put("bar", {"title": "foo1"}),
jio.put("bar", {"title3": "foo3"})
jio.put("bar", {"title": "foo2"}),
]
jio.put("bar", {"title": "foo3"}),
);
jio.put("bar", {"title": "foo4"})
//.push(function () {return jio.get("bar"); })
])
jio.get("bar")
.push(function () {return jio.get("bar"); })
.push(function (result) {equal(result._revision, 3, "parallel exec"); })
.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); })
.fail(function (error) {ok(false, error); })
.always(function () {start(); });
.always(function () {start(); });
});
});
**/
**/
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
...
@@ -53,8 +75,8 @@
...
@@ -53,8 +75,8 @@
module
(
"
bryanStorage.revision_history
"
);
module
(
"
bryanStorage.revision_history
"
);
test
(
"
put and get the correct version
"
,
function
()
{
test
(
"
put and get the correct version
"
,
function
()
{
stop
();
stop
();
expect
(
4
);
expect
(
7
);
var
dbname
=
"
fresh
db0
"
,
var
dbname
=
"
rev_hist_
db0
"
,
jio
=
jIO
.
createJIO
({
jio
=
jIO
.
createJIO
({
type
:
"
bryan
"
,
type
:
"
bryan
"
,
sub_storage
:
{
sub_storage
:
{
...
@@ -76,20 +98,22 @@
...
@@ -76,20 +98,22 @@
database
:
dbname
database
:
dbname
}
}
}
}
});
}),
query_input
=
{
query
:
'
NOT (_deprecated: "true")
'
,
sort_on
:
[[
'
_revision
'
,
'
descending
'
]]
},
query_input2
=
{
query
:
'
title: "rev1"
'
,
sort_on
:
[[
'
_revision
'
,
'
descending
'
]]
};
jio
.
put
(
"
doc1
"
,
{
jio
.
put
(
"
doc1
"
,
{
"
title
"
:
"
rev0
"
,
"
title
"
:
"
rev0
"
,
"
subtitle
"
:
"
subrev0
"
"
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
()
{
.
push
(
function
()
{
return
jio
.
put
(
"
doc1
"
,
{
return
jio
.
put
(
"
doc1
"
,
{
"
title
"
:
"
rev1
"
,
"
title
"
:
"
rev1
"
,
...
@@ -103,60 +127,66 @@
...
@@ -103,60 +127,66 @@
});
});
})
})
.
push
(
function
()
{
.
push
(
function
()
{
return
jio
.
get
(
"
doc1
"
);
return
jio
.
put
(
"
doc1
"
,
{
"
title
"
:
"
rev3
"
,
"
subtitle
"
:
"
subrev3
"
});
})
})
.
push
(
function
()
{
return
jio
.
get
(
"
doc1
"
);
})
.
push
(
function
(
result
)
{
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
deepEqual
(
result
,
{
"
title
"
:
"
rev
2
"
,
"
title
"
:
"
rev
3
"
,
"
subtitle
"
:
"
subrev
2
"
"
subtitle
"
:
"
subrev
3
"
},
"
Retrieve
second
edition of document correctly
"
);
},
"
Retrieve
first
edition of document correctly
"
);
})
})
.
push
(
function
()
{
.
push
(
function
()
{
var
options
=
{
query
:
"
title: rev0
"
};
return
not_bryan
.
allDocs
(
query_input
);
return
jio
.
allDocs
(
options
);
})
})
.
push
(
function
(
results
)
{
.
push
(
function
(
results
)
{
console
.
log
(
"
query results:
"
,
results
);
equal
(
results
.
data
.
rows
.
length
,
1
,
"
Only 1 version isn't _deprecated
"
);
equal
(
results
.
data
.
rows
.
length
,
1
,
"
Query only returns latest version
"
);
return
jio
.
get
(
results
.
data
.
rows
[
0
].
id
);
if
(
results
.
data
.
rows
.
length
>
0
)
{
return
jio
.
get
(
results
.
data
.
rows
[
0
].
id
);
}
})
})
.
push
(
function
(
result
)
{
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
deepEqual
(
result
,
{
"
title
"
:
"
rev
2
"
,
"
title
"
:
"
rev
3
"
,
"
subtitle
"
:
"
subrev
2
"
"
subtitle
"
:
"
subrev
3
"
},
"
Retrieve
queried document correctly
"
);
},
"
Retrieve
most recent edition by querying NOT _deprecated
"
);
})
})
// When not_bryan queries the storage, all documents are returned.
.
push
(
function
()
{
.
push
(
function
()
{
var
options
=
{
return
not_bryan
.
allDocs
(
query_input2
);
query
:
""
,
sort_on
:
[[
"
_revision
"
,
"
ascending
"
]]
};
return
jio
.
allDocs
(
options
);
})
})
.
push
(
function
(
results
)
{
.
push
(
function
(
results
)
{
equal
(
results
.
length
,
2
,
"
should get all 2 revisions.
"
);
equal
(
results
.
data
.
rows
.
length
,
1
,
"
Only one version is titled 'rev1'
"
);
if
(
results
.
length
>
0
)
{
return
jio
.
get
(
results
.
data
.
rows
[
0
].
id
);
return
not_bryan
.
get
(
results
[
0
].
id
);
}
})
})
.
push
(
function
(
result
s
)
{
.
push
(
function
(
result
)
{
deepEqual
(
result
s
,
{
deepEqual
(
result
,
{
"
title
"
:
"
rev
0
"
,
"
title
"
:
"
rev
1
"
,
"
subtitle
"
:
"
subrev
0
"
,
"
subtitle
"
:
"
subrev
1
"
,
"
_d
oc_id
"
:
"
doc1
"
,
"
_d
eprecated
"
:
"
true
"
,
"
_revision
"
:
0
,
"
_revision
"
:
1
,
"
_d
eprecated
"
:
true
"
_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
)
{
.
fail
(
function
(
error
)
{
console
.
log
(
error
);
//
console.log(error);
ok
(
false
,
error
);
ok
(
false
,
error
);
})
})
.
always
(
function
()
{
.
always
(
function
()
{
...
@@ -164,25 +194,35 @@
...
@@ -164,25 +194,35 @@
});
});
});
});
/////////////////////////////////////////////////////////////////
// bryanStorage.revision_history_multiple_edits
/////////////////////////////////////////////////////////////////
module
(
"
bryanStorage.revision_history_multiple_edits
"
);
module
(
"
bryanStorage.revision_history_multiple_edits
"
);
test
(
"
modify first version but save both
"
,
function
()
{
test
(
"
modify first version but save both
"
,
function
()
{
stop
();
stop
();
expect
(
7
);
expect
(
11
);
var
jio
=
jIO
.
createJIO
({
var
dbname
=
"
testdb20
"
,
jio
=
jIO
.
createJIO
({
type
:
"
bryan
"
,
type
:
"
bryan
"
,
sub_storage
:
{
sub_storage
:
{
type
:
"
uuid
"
,
type
:
"
uuid
"
,
sub_storage
:
{
sub_storage
:
{
type
:
"
indexeddb
"
,
type
:
"
indexeddb
"
,
database
:
"
testdb1
"
database
:
dbname
}
}
}
}
}),
}),
not_bryan
=
jIO
.
createJIO
({
not_bryan
=
jIO
.
createJIO
({
type
:
"
uuid
"
,
type
:
"
query
"
,
sub_storage
:
{
sub_storage
:
{
type
:
"
indexeddb
"
,
type
:
"
uuid
"
,
database
:
"
testdb1
"
sub_storage
:
{
type
:
"
indexeddb
"
,
database
:
dbname
}
}
}
});
});
jio
.
put
(
"
main_doc
"
,
{
jio
.
put
(
"
main_doc
"
,
{
...
@@ -239,8 +279,9 @@
...
@@ -239,8 +279,9 @@
});
});
})
})
.
push
(
function
(
result
)
{
.
push
(
function
(
result
)
{
//console.log(result);
equal
(
result
.
data
.
rows
.
length
,
equal
(
result
.
length
,
2
,
"
Empty query returns only non-deprecated docs
"
);
2
,
"
Empty query returns only non-deprecated docs
"
);
})
})
.
push
(
function
()
{
.
push
(
function
()
{
return
jio
.
allDocs
({
return
jio
.
allDocs
({
...
@@ -248,16 +289,18 @@
...
@@ -248,16 +289,18 @@
});
});
})
})
.
push
(
function
(
result
)
{
.
push
(
function
(
result
)
{
//console.log("res:", result);
equal
(
result
.
data
.
rows
.
length
,
if
(
result
.
length
>
0
)
{
1
,
return
jio
.
get
(
result
[
0
].
id
);
"
No deprecated results are returned.
"
);
if
(
result
.
data
.
rows
.
length
>
0
)
{
return
jio
.
get
(
result
.
data
.
rows
[
0
].
id
);
}
}
})
})
.
push
(
function
(
result
)
{
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
deepEqual
(
result
,
{
"
attr
"
:
"
version1
"
,
"
attr
"
:
"
version1
"
,
"
subattr
"
:
"
subversion1
"
"
subattr
"
:
"
subversion1
"
},
"
Retrieve other document correctly
"
);
},
"
Only get most recent edit
"
);
})
})
.
push
(
function
()
{
.
push
(
function
()
{
return
jio
.
allDocs
({
return
jio
.
allDocs
({
...
@@ -265,7 +308,7 @@
...
@@ -265,7 +308,7 @@
});
});
})
})
.
push
(
function
(
result
)
{
.
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
()
{
.
push
(
function
()
{
return
jio
.
allDocs
({
return
jio
.
allDocs
({
...
@@ -273,7 +316,7 @@
...
@@ -273,7 +316,7 @@
});
});
})
})
.
push
(
function
(
result
)
{
.
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
()
{
.
push
(
function
()
{
return
jio
.
allDocs
({
return
jio
.
allDocs
({
...
@@ -281,7 +324,7 @@
...
@@ -281,7 +324,7 @@
});
});
})
})
.
push
(
function
(
result
)
{
.
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.
// When not_bryan queries the storage, all documents are returned.
...
@@ -293,8 +336,10 @@
...
@@ -293,8 +336,10 @@
return
not_bryan
.
allDocs
(
options
);
return
not_bryan
.
allDocs
(
options
);
})
})
.
push
(
function
(
results
)
{
.
push
(
function
(
results
)
{
equal
(
results
.
length
,
3
,
"
should get all 3 deprecated versions.
"
);
equal
(
results
.
data
.
rows
.
length
,
return
not_bryan
.
get
(
results
[
0
].
id
);
3
,
"
should get all 3 deprecated versions.
"
);
return
not_bryan
.
get
(
results
.
data
.
rows
[
0
].
id
);
})
})
.
push
(
function
(
results
)
{
.
push
(
function
(
results
)
{
deepEqual
(
results
,
{
deepEqual
(
results
,
{
...
@@ -302,7 +347,7 @@
...
@@ -302,7 +347,7 @@
"
subtitle
"
:
"
subrev0
"
,
"
subtitle
"
:
"
subrev0
"
,
"
_doc_id
"
:
"
main_doc
"
,
"
_doc_id
"
:
"
main_doc
"
,
"
_revision
"
:
0
,
"
_revision
"
:
0
,
"
_deprecated
"
:
true
"
_deprecated
"
:
"
true
"
},
},
"
Get the earliest copy of the doc with all metadata.
"
);
"
Get the earliest copy of the doc with all metadata.
"
);
})
})
...
@@ -316,7 +361,7 @@
...
@@ -316,7 +361,7 @@
return
not_bryan
.
allDocs
(
options
);
return
not_bryan
.
allDocs
(
options
);
})
})
.
push
(
function
(
results
)
{
.
push
(
function
(
results
)
{
return
not_bryan
.
get
(
results
[
1
].
id
);
return
not_bryan
.
get
(
results
.
data
.
rows
[
1
].
id
);
})
})
.
push
(
function
(
results
)
{
.
push
(
function
(
results
)
{
deepEqual
(
results
,
{
deepEqual
(
results
,
{
...
@@ -324,7 +369,7 @@
...
@@ -324,7 +369,7 @@
"
subtitle
"
:
"
subrev1
"
,
"
subtitle
"
:
"
subrev1
"
,
"
_doc_id
"
:
"
main_doc
"
,
"
_doc_id
"
:
"
main_doc
"
,
"
_revision
"
:
1
,
"
_revision
"
:
1
,
"
_deprecated
"
:
true
"
_deprecated
"
:
"
true
"
},
},
"
Get the earliest copy of the doc with all metadata.
"
);
"
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