Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Junming
jio
Commits
8fb729ac
Commit
8fb729ac
authored
Jan 07, 2013
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
revision generating changed
parent
339eae00
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
13 deletions
+25
-13
src/jio.storage/revisionstorage.js
src/jio.storage/revisionstorage.js
+9
-3
test/jiotests.js
test/jiotests.js
+16
-10
No files found.
src/jio.storage/revisionstorage.js
View file @
8fb729ac
...
@@ -74,10 +74,15 @@ jIO.addStorageType('revision', function (spec, my) {
...
@@ -74,10 +74,15 @@ jIO.addStorageType('revision', function (spec, my) {
* to generate a hash code.
* to generate a hash code.
* @methode generateNextRev
* @methode generateNextRev
* @param {string} previous_revision The previous revision
* @param {string} previous_revision The previous revision
* @param {string} string String to help generate hash code
* @param {object} doc The document metadata
* @param {object} revisions The revision history
* @param {boolean} deleted_flag The deleted flag
* @return {array} 0:The next revision number and 1:the hash code
* @return {array} 0:The next revision number and 1:the hash code
*/
*/
priv
.
generateNextRevision
=
function
(
previous_revision
,
string
)
{
priv
.
generateNextRevision
=
function
(
previous_revision
,
doc
,
revisions
,
deleted_flag
)
{
var
string
=
JSON
.
stringify
(
doc
)
+
JSON
.
stringify
(
revisions
)
+
JSON
.
stringify
(
deleted_flag
?
true
:
false
);
if
(
typeof
previous_revision
===
"
number
"
)
{
if
(
typeof
previous_revision
===
"
number
"
)
{
return
[
previous_revision
+
1
,
priv
.
hashCode
(
string
)];
return
[
previous_revision
+
1
,
priv
.
hashCode
(
string
)];
}
}
...
@@ -247,7 +252,8 @@ jIO.addStorageType('revision', function (spec, my) {
...
@@ -247,7 +252,8 @@ jIO.addStorageType('revision', function (spec, my) {
}
}
}
}
next_rev
=
priv
.
generateNextRevision
(
next_rev
=
priv
.
generateNextRevision
(
doc
.
_rev
||
0
,
JSON
.
stringify
(
doc
)
+
JSON
.
stringify
(
revs_info
));
doc
.
_rev
||
0
,
doc
,
priv
.
revsInfoToHistory
(
revs_info
),
set_node_to_deleted
);
next_rev_str
=
next_rev
.
join
(
"
-
"
);
next_rev_str
=
next_rev
.
join
(
"
-
"
);
next_rev_status
=
set_node_to_deleted
===
true
?
"
deleted
"
:
"
available
"
;
next_rev_status
=
set_node_to_deleted
===
true
?
"
deleted
"
:
"
available
"
;
...
...
test/jiotests.js
View file @
8fb729ac
...
@@ -21,6 +21,13 @@ contains = function (array,content) {
...
@@ -21,6 +21,13 @@ contains = function (array,content) {
clone
=
function
(
obj
)
{
clone
=
function
(
obj
)
{
return
JSON
.
parse
(
JSON
.
stringify
(
obj
));
return
JSON
.
parse
(
JSON
.
stringify
(
obj
));
},
},
// generates a revision hash from document metadata, revision history
// and the deleted_flag
generateRevisionHash
=
function
(
doc
,
revisions
,
deleted_flag
)
{
var
string
=
JSON
.
stringify
(
doc
)
+
JSON
.
stringify
(
revisions
)
+
JSON
.
stringify
(
deleted_flag
?
true
:
false
);
return
hex_sha256
(
string
);
},
// localStorage wrapper
// localStorage wrapper
localstorage
=
{
localstorage
=
{
clear
:
function
()
{
clear
:
function
()
{
...
@@ -1086,8 +1093,8 @@ test ("Post", function(){
...
@@ -1086,8 +1093,8 @@ test ("Post", function(){
// post non empty document
// post non empty document
o
.
doc
=
{
"
_id
"
:
"
post1
"
,
"
title
"
:
"
myPost1
"
};
o
.
doc
=
{
"
_id
"
:
"
post1
"
,
"
title
"
:
"
myPost1
"
};
o
.
rev
s_info
=
[]
;
o
.
rev
isions
=
{
"
start
"
:
0
,
"
ids
"
:
[]}
;
o
.
rev
=
"
1-
"
+
hex_sha256
(
JSON
.
stringify
(
o
.
doc
)
+
JSON
.
stringify
(
o
.
revs_info
)
);
o
.
rev
=
"
1-
"
+
generateRevisionHash
(
o
.
doc
,
o
.
revisions
);
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
post1
"
,
"
rev
"
:
o
.
rev
},
"
Post
"
);
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
post1
"
,
"
rev
"
:
o
.
rev
},
"
Post
"
);
o
.
jio
.
post
(
o
.
doc
,
o
.
f
);
o
.
jio
.
post
(
o
.
doc
,
o
.
f
);
o
.
tick
(
o
);
o
.
tick
(
o
);
...
@@ -1101,8 +1108,7 @@ test ("Post", function(){
...
@@ -1101,8 +1108,7 @@ test ("Post", function(){
// post and document already exists
// post and document already exists
o
.
doc
=
{
"
_id
"
:
"
post1
"
,
"
title
"
:
"
myPost2
"
};
o
.
doc
=
{
"
_id
"
:
"
post1
"
,
"
title
"
:
"
myPost2
"
};
o
.
revs_info
=
[];
o
.
rev
=
"
1-
"
+
generateRevisionHash
(
o
.
doc
,
o
.
revisions
);
o
.
rev
=
"
1-
"
+
hex_sha256
(
JSON
.
stringify
(
o
.
doc
)
+
JSON
.
stringify
(
o
.
revs_info
));
o
.
spy
(
o
,
"
value
"
,
{
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
post1
"
,
"
rev
"
:
o
.
rev
"
ok
"
:
true
,
"
id
"
:
"
post1
"
,
"
rev
"
:
o
.
rev
},
"
Post and document already exists
"
);
},
"
Post and document already exists
"
);
...
@@ -1111,8 +1117,8 @@ test ("Post", function(){
...
@@ -1111,8 +1117,8 @@ test ("Post", function(){
// post + revision
// post + revision
o
.
doc
=
{
"
_id
"
:
"
post1
"
,
"
_rev
"
:
o
.
rev
,
"
title
"
:
"
myPost2
"
};
o
.
doc
=
{
"
_id
"
:
"
post1
"
,
"
_rev
"
:
o
.
rev
,
"
title
"
:
"
myPost2
"
};
o
.
rev
s_info
=
[{
"
rev
"
:
o
.
rev
,
"
status
"
:
"
available
"
}]
;
o
.
rev
isions
=
{
"
start
"
:
1
,
"
ids
"
:
[
o
.
rev
.
split
(
'
-
'
)[
1
]]}
;
o
.
rev
=
"
2-
"
+
hex_sha256
(
JSON
.
stringify
(
o
.
doc
)
+
JSON
.
stringify
(
o
.
revs_info
)
);
o
.
rev
=
"
2-
"
+
generateRevisionHash
(
o
.
doc
,
o
.
revisions
);
o
.
spy
(
o
,
"
status
"
,
undefined
,
"
Post + revision
"
);
o
.
spy
(
o
,
"
status
"
,
undefined
,
"
Post + revision
"
);
o
.
jio
.
post
(
o
.
doc
,
o
.
f
);
o
.
jio
.
post
(
o
.
doc
,
o
.
f
);
o
.
tick
(
o
);
o
.
tick
(
o
);
...
@@ -1152,8 +1158,8 @@ test ("Put", function(){
...
@@ -1152,8 +1158,8 @@ test ("Put", function(){
// put non empty document
// put non empty document
o
.
doc
=
{
"
_id
"
:
"
put1
"
,
"
title
"
:
"
myPut1
"
};
o
.
doc
=
{
"
_id
"
:
"
put1
"
,
"
title
"
:
"
myPut1
"
};
o
.
rev
s_info
=
[]
;
o
.
rev
isions
=
{
"
start
"
:
0
,
"
ids
"
:
[]}
;
o
.
rev
=
"
1-
"
+
hex_sha256
(
JSON
.
stringify
(
o
.
doc
)
+
JSON
.
stringify
(
o
.
revs_info
)
);
o
.
rev
=
"
1-
"
+
generateRevisionHash
(
o
.
doc
,
o
.
revisions
);
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
put1
"
,
"
rev
"
:
o
.
rev
},
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
put1
"
,
"
rev
"
:
o
.
rev
},
"
Creates a document
"
);
"
Creates a document
"
);
o
.
jio
.
put
(
o
.
doc
,
o
.
f
);
o
.
jio
.
put
(
o
.
doc
,
o
.
f
);
...
@@ -1173,8 +1179,8 @@ test ("Put", function(){
...
@@ -1173,8 +1179,8 @@ test ("Put", function(){
// post + revision
// post + revision
o
.
doc
=
{
"
_id
"
:
"
put1
"
,
"
_rev
"
:
o
.
rev
,
"
title
"
:
"
myPut2
"
};
o
.
doc
=
{
"
_id
"
:
"
put1
"
,
"
_rev
"
:
o
.
rev
,
"
title
"
:
"
myPut2
"
};
o
.
rev
s_info
=
[{
"
rev
"
:
o
.
rev
,
"
status
"
:
"
available
"
}]
;
o
.
rev
isions
=
{
"
start
"
:
1
,
"
ids
"
:
[
o
.
rev
.
split
(
'
-
'
)[
1
]]}
;
o
.
rev
=
"
2-
"
+
hex_sha256
(
JSON
.
stringify
(
o
.
doc
)
+
JSON
.
stringify
(
o
.
revs_info
)
);
o
.
rev
=
"
2-
"
+
generateRevisionHash
(
o
.
doc
,
o
.
revisions
);
o
.
spy
(
o
,
"
status
"
,
undefined
,
"
Put + revision
"
);
o
.
spy
(
o
,
"
status
"
,
undefined
,
"
Put + revision
"
);
o
.
jio
.
put
(
o
.
doc
,
o
.
f
);
o
.
jio
.
put
(
o
.
doc
,
o
.
f
);
o
.
tick
(
o
);
o
.
tick
(
o
);
...
...
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