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
Xiaowu Zhang
jio
Commits
bc17b228
Commit
bc17b228
authored
Jan 10, 2013
by
Sven Franck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
jslint pass revisionstorage.js
parent
e45edf9f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
834 additions
and
826 deletions
+834
-826
src/jio.storage/revisionstorage.js
src/jio.storage/revisionstorage.js
+834
-826
No files found.
src/jio.storage/revisionstorage.js
View file @
bc17b228
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true */
/*global jIO: true, hex_sha256: true, setTimeout: true */
/**
/**
* JIO Revision Storage.
* JIO Revision Storage.
* It manages document version and can generate conflicts.
* It manages document version and can generate conflicts.
...
@@ -30,19 +32,17 @@ jIO.addStorageType('revision', function (spec, my) {
...
@@ -30,19 +32,17 @@ jIO.addStorageType('revision', function (spec, my) {
*/
*/
priv
.
generateUuid
=
function
()
{
priv
.
generateUuid
=
function
()
{
var
S4
=
function
()
{
var
S4
=
function
()
{
/* 65536 */
var
i
,
string
=
Math
.
floor
(
var
i
,
string
=
Math
.
floor
(
Math
.
random
()
*
0x10000
/* 65536 */
Math
.
random
()
*
0x10000
).
toString
(
16
);
).
toString
(
16
);
for
(
i
=
string
.
length
;
i
<
4
;
i
+=
1
)
{
for
(
i
=
string
.
length
;
i
<
4
;
i
+=
1
)
{
string
=
'
0
'
+
string
;
string
=
'
0
'
+
string
;
}
}
return
string
;
return
string
;
};
};
return
S4
()
+
S4
()
+
"
-
"
+
return
S4
()
+
S4
()
+
"
-
"
+
S4
()
+
"
-
"
+
S4
()
+
"
-
"
+
S4
()
+
"
-
"
+
S4
()
+
S4
()
+
"
-
"
+
S4
()
+
S4
();
S4
()
+
"
-
"
+
S4
()
+
"
-
"
+
S4
()
+
S4
()
+
S4
();
};
};
/**
/**
...
@@ -63,8 +63,8 @@ jIO.addStorageType('revision', function (spec, my) {
...
@@ -63,8 +63,8 @@ jIO.addStorageType('revision', function (spec, my) {
*/
*/
priv
.
revisionToArray
=
function
(
revision
)
{
priv
.
revisionToArray
=
function
(
revision
)
{
if
(
typeof
revision
===
"
string
"
)
{
if
(
typeof
revision
===
"
string
"
)
{
return
[
parseInt
(
revision
.
split
(
'
-
'
)[
0
],
10
),
return
[
parseInt
(
revision
.
split
(
'
-
'
)[
0
],
10
),
revision
.
split
(
'
-
'
)[
1
]]
revision
.
split
(
'
-
'
)[
1
]];
}
}
return
revision
;
return
revision
;
};
};
...
@@ -82,12 +82,12 @@ jIO.addStorageType('revision', function (spec, my) {
...
@@ -82,12 +82,12 @@ jIO.addStorageType('revision', function (spec, my) {
priv
.
generateNextRevision
=
function
(
previous_revision
,
priv
.
generateNextRevision
=
function
(
previous_revision
,
doc
,
revisions
,
deleted_flag
)
{
doc
,
revisions
,
deleted_flag
)
{
var
string
=
JSON
.
stringify
(
doc
)
+
JSON
.
stringify
(
revisions
)
+
var
string
=
JSON
.
stringify
(
doc
)
+
JSON
.
stringify
(
revisions
)
+
JSON
.
stringify
(
deleted_flag
?
true
:
false
);
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
)];
}
}
previous_revision
=
priv
.
revisionToArray
(
previous_revision
);
previous_revision
=
priv
.
revisionToArray
(
previous_revision
);
return
[
previous_revision
[
0
]
+
1
,
priv
.
hashCode
(
string
)];
return
[
previous_revision
[
0
]
+
1
,
priv
.
hashCode
(
string
)];
};
};
/**
/**
...
@@ -106,8 +106,10 @@ jIO.addStorageType('revision', function (spec, my) {
...
@@ -106,8 +106,10 @@ jIO.addStorageType('revision', function (spec, my) {
* @param {array} children An array of children (optional)
* @param {array} children An array of children (optional)
* @return {object} The new document tree
* @return {object} The new document tree
*/
*/
priv
.
createDocumentTree
=
function
(
children
)
{
priv
.
createDocumentTree
=
function
(
children
)
{
return
{
"
children
"
:
children
||
[]};
return
{
"
children
"
:
children
||
[]
};
};
};
/**
/**
...
@@ -118,8 +120,12 @@ jIO.addStorageType('revision', function (spec, my) {
...
@@ -118,8 +120,12 @@ jIO.addStorageType('revision', function (spec, my) {
* @param {array} children An array of children (optional)
* @param {array} children An array of children (optional)
* @return {object} The new document tree node
* @return {object} The new document tree node
*/
*/
priv
.
createDocumentTreeNode
=
function
(
revision
,
status
,
children
)
{
priv
.
createDocumentTreeNode
=
function
(
revision
,
status
,
children
)
{
return
{
"
rev
"
:
revision
,
"
status
"
:
status
,
"
children
"
:
children
||
[]};
return
{
"
rev
"
:
revision
,
"
status
"
:
status
,
"
children
"
:
children
||
[]
};
};
};
/**
/**
...
@@ -130,16 +136,16 @@ jIO.addStorageType('revision', function (spec, my) {
...
@@ -130,16 +136,16 @@ jIO.addStorageType('revision', function (spec, my) {
* @return {array} The good revs info array
* @return {array} The good revs info array
*/
*/
priv
.
getRevisionFromDocumentTree
=
function
(
document_tree
,
revision
)
{
priv
.
getRevisionFromDocumentTree
=
function
(
document_tree
,
revision
)
{
var
i
,
result
,
search
,
revs_info
=
[];
var
result
,
search
,
revs_info
=
[];
result
=
[];
result
=
[];
// search method fills "result" with the good revs info
// search method fills "result" with the good revs info
search
=
function
(
document_tree
)
{
search
=
function
(
document_tree
)
{
var
i
;
var
i
;
if
(
typeof
document_tree
.
rev
!==
"
undefined
"
)
{
if
(
document_tree
.
rev
!==
undefined
)
{
// node is not root
// node is not root
revs_info
.
unshift
({
revs_info
.
unshift
({
"
rev
"
:
document_tree
.
rev
,
"
rev
"
:
document_tree
.
rev
,
"
status
"
:
document_tree
.
status
"
status
"
:
document_tree
.
status
});
});
if
(
document_tree
.
rev
===
revision
)
{
if
(
document_tree
.
rev
===
revision
)
{
result
=
revs_info
;
result
=
revs_info
;
...
@@ -169,20 +175,20 @@ jIO.addStorageType('revision', function (spec, my) {
...
@@ -169,20 +175,20 @@ jIO.addStorageType('revision', function (spec, my) {
* @return {array} The winner revs info array
* @return {array} The winner revs info array
*/
*/
priv
.
getWinnerRevisionFromDocumentTree
=
function
(
document_tree
)
{
priv
.
getWinnerRevisionFromDocumentTree
=
function
(
document_tree
)
{
var
i
,
result
,
search
,
revs_info
=
[];
var
result
,
search
,
revs_info
=
[];
result
=
[];
result
=
[];
// search method fills "result" with the winner revs info
// search method fills "result" with the winner revs info
search
=
function
(
document_tree
,
deep
)
{
search
=
function
(
document_tree
,
deep
)
{
var
i
;
var
i
;
if
(
typeof
document_tree
.
rev
!==
"
undefined
"
)
{
if
(
document_tree
.
rev
!==
undefined
)
{
// node is not root
// node is not root
revs_info
.
unshift
({
revs_info
.
unshift
({
"
rev
"
:
document_tree
.
rev
,
"
rev
"
:
document_tree
.
rev
,
"
status
"
:
document_tree
.
status
"
status
"
:
document_tree
.
status
});
});
}
}
if
(
document_tree
.
children
.
length
===
0
&&
if
(
document_tree
.
children
.
length
===
0
&&
document_tree
.
status
!==
document_tree
.
status
!==
"
deleted
"
)
{
"
deleted
"
)
{
// This node is a leaf
// This node is a leaf
if
(
result
.
length
<
deep
)
{
if
(
result
.
length
<
deep
)
{
// The leaf is deeper than result
// The leaf is deeper than result
...
@@ -196,7 +202,7 @@ jIO.addStorageType('revision', function (spec, my) {
...
@@ -196,7 +202,7 @@ jIO.addStorageType('revision', function (spec, my) {
// This node has children
// This node has children
for
(
i
=
0
;
i
<
document_tree
.
children
.
length
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
document_tree
.
children
.
length
;
i
+=
1
)
{
// searching deeper to find the deeper leaf
// searching deeper to find the deeper leaf
search
(
document_tree
.
children
[
i
],
deep
+
1
);
search
(
document_tree
.
children
[
i
],
deep
+
1
);
revs_info
.
shift
();
revs_info
.
shift
();
}
}
};
};
...
@@ -220,21 +226,23 @@ jIO.addStorageType('revision', function (spec, my) {
...
@@ -220,21 +226,23 @@ jIO.addStorageType('revision', function (spec, my) {
selected_node
=
doctree
;
selected_node
=
doctree
;
selectNode
=
function
(
node
)
{
selectNode
=
function
(
node
)
{
var
i
;
var
i
;
if
(
typeof
node
.
rev
!==
"
undefined
"
)
{
if
(
node
.
rev
!==
undefined
)
{
// node is not root
// node is not root
revs_info
.
unshift
({
"
rev
"
:
node
.
rev
,
"
status
"
:
node
.
status
});
revs_info
.
unshift
({
"
rev
"
:
node
.
rev
,
"
status
"
:
node
.
status
});
}
}
if
(
node
.
rev
===
doc
.
_rev
)
{
if
(
node
.
rev
===
doc
.
_rev
)
{
selected_node
=
node
;
selected_node
=
node
;
return
"
node_selected
"
;
return
"
node_selected
"
;
}
else
{
}
for
(
i
=
0
;
i
<
node
.
children
.
length
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
node
.
children
.
length
;
i
+=
1
)
{
if
(
selectNode
(
node
.
children
[
i
])
===
"
node_selected
"
)
{
if
(
selectNode
(
node
.
children
[
i
])
===
"
node_selected
"
)
{
return
"
node_selected
"
;
return
"
node_selected
"
;
}
}
revs_info
.
shift
();
revs_info
.
shift
();
}
}
}
};
};
if
(
typeof
doc
.
_rev
===
"
string
"
)
{
if
(
typeof
doc
.
_rev
===
"
string
"
)
{
// document has a previous revision
// document has a previous revision
...
@@ -253,8 +261,11 @@ jIO.addStorageType('revision', function (spec, my) {
...
@@ -253,8 +261,11 @@ jIO.addStorageType('revision', function (spec, my) {
}
}
}
}
next_rev
=
priv
.
generateNextRevision
(
next_rev
=
priv
.
generateNextRevision
(
doc
.
_rev
||
0
,
doc
,
priv
.
revsInfoToHistory
(
revs_info
),
doc
.
_rev
||
0
,
set_node_to_deleted
);
doc
,
priv
.
revsInfoToHistory
(
revs_info
),
set_node_to_deleted
);
next_rev_str
=
next_rev
.
join
(
"
-
"
);
next_rev_str
=
next_rev
.
join
(
"
-
"
);
// don't add if the next rev already exists
// don't add if the next rev already exists
for
(
i
=
0
;
i
<
selected_node
.
children
.
length
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
selected_node
.
children
.
length
;
i
+=
1
)
{
...
@@ -291,7 +302,7 @@ jIO.addStorageType('revision', function (spec, my) {
...
@@ -291,7 +302,7 @@ jIO.addStorageType('revision', function (spec, my) {
* @return {array} The array of leaves revisions
* @return {array} The array of leaves revisions
*/
*/
priv
.
getLeavesFromDocumentTree
=
function
(
document_tree
,
except
)
{
priv
.
getLeavesFromDocumentTree
=
function
(
document_tree
,
except
)
{
var
i
,
result
,
search
;
var
result
,
search
;
result
=
[];
result
=
[];
// search method fills [result] with the winner revision
// search method fills [result] with the winner revision
search
=
function
(
document_tree
)
{
search
=
function
(
document_tree
)
{
...
@@ -299,8 +310,8 @@ jIO.addStorageType('revision', function (spec, my) {
...
@@ -299,8 +310,8 @@ jIO.addStorageType('revision', function (spec, my) {
if
(
except
!==
undefined
&&
except
===
document_tree
.
rev
)
{
if
(
except
!==
undefined
&&
except
===
document_tree
.
rev
)
{
return
;
return
;
}
}
if
(
document_tree
.
children
.
length
===
0
&&
if
(
document_tree
.
children
.
length
===
0
&&
document_tree
.
status
!==
document_tree
.
status
!==
"
deleted
"
)
{
"
deleted
"
)
{
// This node is a leaf
// This node is a leaf
result
.
push
(
document_tree
.
rev
);
result
.
push
(
document_tree
.
rev
);
return
;
return
;
...
@@ -323,17 +334,17 @@ jIO.addStorageType('revision', function (spec, my) {
...
@@ -323,17 +334,17 @@ jIO.addStorageType('revision', function (spec, my) {
* @return {boolean} true/false
* @return {boolean} true/false
*/
*/
priv
.
isRevisionALeaf
=
function
(
document_tree
,
revision
)
{
priv
.
isRevisionALeaf
=
function
(
document_tree
,
revision
)
{
var
i
,
result
,
search
;
var
result
,
search
;
result
=
undefined
;
result
=
undefined
;
// search method fills "result" with the good revs info
// search method fills "result" with the good revs info
search
=
function
(
document_tree
)
{
search
=
function
(
document_tree
)
{
var
i
;
var
i
;
if
(
typeof
document_tree
.
rev
!==
"
undefined
"
)
{
if
(
document_tree
.
rev
!==
undefined
)
{
// node is not root
// node is not root
if
(
document_tree
.
rev
===
revision
)
{
if
(
document_tree
.
rev
===
revision
)
{
if
(
document_tree
.
children
.
length
===
0
)
{
if
(
document_tree
.
children
.
length
===
0
)
{
// This node is a leaf
// This node is a leaf
result
=
true
result
=
true
;
return
;
return
;
}
}
result
=
false
;
result
=
false
;
...
@@ -361,9 +372,12 @@ jIO.addStorageType('revision', function (spec, my) {
...
@@ -361,9 +372,12 @@ jIO.addStorageType('revision', function (spec, my) {
* @return {object} The revisions history
* @return {object} The revisions history
*/
*/
priv
.
revsInfoToHistory
=
function
(
revs_info
)
{
priv
.
revsInfoToHistory
=
function
(
revs_info
)
{
var
revisions
=
{
"
start
"
:
0
,
"
ids
"
:[]},
i
;
var
revisions
=
{
"
start
"
:
0
,
"
ids
"
:
[]
},
i
;
if
(
revs_info
.
length
>
0
)
{
if
(
revs_info
.
length
>
0
)
{
revisions
.
start
=
parseInt
(
revs_info
[
0
].
rev
.
split
(
'
-
'
)[
0
],
10
);
revisions
.
start
=
parseInt
(
revs_info
[
0
].
rev
.
split
(
'
-
'
)[
0
],
10
);
}
}
for
(
i
=
0
;
i
<
revs_info
.
length
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
revs_info
.
length
;
i
+=
1
)
{
revisions
.
ids
.
push
(
revs_info
[
i
].
rev
.
split
(
'
-
'
)[
1
]);
revisions
.
ids
.
push
(
revs_info
[
i
].
rev
.
split
(
'
-
'
)[
1
]);
...
@@ -401,13 +415,12 @@ jIO.addStorageType('revision', function (spec, my) {
...
@@ -401,13 +415,12 @@ jIO.addStorageType('revision', function (spec, my) {
doc
=
command
.
cloneDoc
();
doc
=
command
.
cloneDoc
();
docid
=
command
.
getDocId
();
docid
=
command
.
getDocId
();
if
(
typeof
doc
.
_rev
===
"
string
"
&&
if
(
typeof
doc
.
_rev
===
"
string
"
&&
!
priv
.
checkRevisionFormat
(
doc
.
_rev
))
{
!
priv
.
checkRevisionFormat
(
doc
.
_rev
))
{
that
.
error
({
that
.
error
({
"
status
"
:
31
,
"
status
"
:
31
,
"
statusText
"
:
"
Wrong Revision Format
"
,
"
statusText
"
:
"
Wrong Revision Format
"
,
"
error
"
:
"
wrong_revision_format
"
,
"
error
"
:
"
wrong_revision_format
"
,
"
message
"
:
"
The document previous revision does not match
"
+
"
message
"
:
"
The document previous revision does not match
"
+
"
^[0-9]+-[0-9a-zA-Z]+$
"
,
"
^[0-9]+-[0-9a-zA-Z]+$
"
,
"
reason
"
:
"
Previous revision is wrong
"
"
reason
"
:
"
Previous revision is wrong
"
});
});
...
@@ -422,14 +435,15 @@ jIO.addStorageType('revision', function (spec, my) {
...
@@ -422,14 +435,15 @@ jIO.addStorageType('revision', function (spec, my) {
}
}
f
.
getDocumentTree
=
function
()
{
f
.
getDocumentTree
=
function
()
{
var
option
=
command
.
cloneOption
();
var
option
=
command
.
cloneOption
();
if
(
option
[
"
max_retry
"
]
===
0
)
{
if
(
option
.
max_retry
===
0
)
{
option
[
"
max_retry
"
]
=
3
;
option
.
max_retry
=
3
;
}
}
that
.
addJob
(
that
.
addJob
(
"
get
"
,
"
get
"
,
priv
.
substorage
,
priv
.
substorage
,
docid
+
priv
.
doctree_suffix
,
docid
+
priv
.
doctree_suffix
,
option
,
option
,
function
(
response
)
{
function
(
response
)
{
doctree
=
response
;
doctree
=
response
;
...
@@ -444,8 +458,9 @@ jIO.addStorageType('revision', function (spec, my) {
...
@@ -444,8 +458,9 @@ jIO.addStorageType('revision', function (spec, my) {
"
reason
"
:
"
Document update conflict
"
"
reason
"
:
"
Document update conflict
"
});
});
}
}
},
function
(
err
)
{
},
switch
(
err
.
status
)
{
function
(
err
)
{
switch
(
err
.
status
)
{
case
404
:
case
404
:
doctree
=
priv
.
createDocumentTree
();
doctree
=
priv
.
createDocumentTree
();
f
.
postDocument
(
"
post
"
);
f
.
postDocument
(
"
post
"
);
...
@@ -460,23 +475,23 @@ jIO.addStorageType('revision', function (spec, my) {
...
@@ -460,23 +475,23 @@ jIO.addStorageType('revision', function (spec, my) {
};
};
f
.
postDocument
=
function
(
doctree_update_method
)
{
f
.
postDocument
=
function
(
doctree_update_method
)
{
revs_info
=
priv
.
postToDocumentTree
(
doctree
,
doc
);
revs_info
=
priv
.
postToDocumentTree
(
doctree
,
doc
);
doc
.
_id
=
docid
+
"
.
"
+
revs_info
[
0
].
rev
;
doc
.
_id
=
docid
+
"
.
"
+
revs_info
[
0
].
rev
;
that
.
addJob
(
that
.
addJob
(
"
post
"
,
"
post
"
,
priv
.
substorage
,
priv
.
substorage
,
doc
,
doc
,
command
.
cloneOption
(),
command
.
cloneOption
(),
function
(
response
)
{
function
(
)
{
f
.
sendDocumentTree
(
doctree_update_method
);
f
.
sendDocumentTree
(
doctree_update_method
);
},
},
function
(
err
)
{
function
(
err
)
{
switch
(
err
.
status
)
{
switch
(
err
.
status
)
{
case
409
:
case
409
:
// file already exists
// file already exists
f
.
sendDocumentTree
(
doctree_update_method
);
f
.
sendDocumentTree
(
doctree_update_method
);
break
;
break
;
default
:
default
:
err
.
message
=
"
Cannot upload document
"
.
err
.
message
=
"
Cannot upload document
"
;
that
.
error
(
err
);
that
.
error
(
err
);
break
;
break
;
}
}
...
@@ -484,17 +499,17 @@ jIO.addStorageType('revision', function (spec, my) {
...
@@ -484,17 +499,17 @@ jIO.addStorageType('revision', function (spec, my) {
);
);
};
};
f
.
sendDocumentTree
=
function
(
method
)
{
f
.
sendDocumentTree
=
function
(
method
)
{
doctree
.
_id
=
docid
+
priv
.
doctree_suffix
;
doctree
.
_id
=
docid
+
priv
.
doctree_suffix
;
that
.
addJob
(
that
.
addJob
(
method
,
method
,
priv
.
substorage
,
priv
.
substorage
,
doctree
,
doctree
,
command
.
cloneOption
(),
command
.
cloneOption
(),
function
(
response
)
{
function
(
)
{
that
.
success
({
that
.
success
({
"
ok
"
:
true
,
"
ok
"
:
true
,
"
id
"
:
docid
,
"
id
"
:
docid
,
"
rev
"
:
revs_info
[
0
].
rev
"
rev
"
:
revs_info
[
0
].
rev
});
});
},
},
function
(
err
)
{
function
(
err
)
{
...
@@ -534,8 +549,8 @@ jIO.addStorageType('revision', function (spec, my) {
...
@@ -534,8 +549,8 @@ jIO.addStorageType('revision', function (spec, my) {
that
.
get
=
function
(
command
)
{
that
.
get
=
function
(
command
)
{
var
f
=
{},
doctree
,
revs_info
,
prev_rev
,
option
;
var
f
=
{},
doctree
,
revs_info
,
prev_rev
,
option
;
option
=
command
.
cloneOption
();
option
=
command
.
cloneOption
();
if
(
option
[
"
max_retry
"
]
===
0
)
{
if
(
option
.
max_retry
===
0
)
{
option
[
"
max_retry
"
]
=
3
;
option
.
max_retry
=
3
;
}
}
prev_rev
=
command
.
getOption
(
"
rev
"
);
prev_rev
=
command
.
getOption
(
"
rev
"
);
if
(
typeof
prev_rev
===
"
string
"
)
{
if
(
typeof
prev_rev
===
"
string
"
)
{
...
@@ -544,7 +559,7 @@ jIO.addStorageType('revision', function (spec, my) {
...
@@ -544,7 +559,7 @@ jIO.addStorageType('revision', function (spec, my) {
"
status
"
:
31
,
"
status
"
:
31
,
"
statusText
"
:
"
Wrong Revision Format
"
,
"
statusText
"
:
"
Wrong Revision Format
"
,
"
error
"
:
"
wrong_revision_format
"
,
"
error
"
:
"
wrong_revision_format
"
,
"
message
"
:
"
The document previous revision does not match
"
+
"
message
"
:
"
The document previous revision does not match
"
+
"
[0-9]+-[0-9a-zA-Z]+
"
,
"
[0-9]+-[0-9a-zA-Z]+
"
,
"
reason
"
:
"
Previous revision is wrong
"
"
reason
"
:
"
Previous revision is wrong
"
});
});
...
@@ -555,22 +570,21 @@ jIO.addStorageType('revision', function (spec, my) {
...
@@ -555,22 +570,21 @@ jIO.addStorageType('revision', function (spec, my) {
that
.
addJob
(
that
.
addJob
(
"
get
"
,
"
get
"
,
priv
.
substorage
,
priv
.
substorage
,
command
.
getDocId
()
+
priv
.
doctree_suffix
,
command
.
getDocId
()
+
priv
.
doctree_suffix
,
option
,
option
,
function
(
response
)
{
function
(
response
)
{
doctree
=
response
;
doctree
=
response
;
if
(
prev_rev
===
undefined
)
{
if
(
prev_rev
===
undefined
)
{
revs_info
=
revs_info
=
priv
.
getWinnerRevisionFromDocumentTree
(
doctree
);
priv
.
getWinnerRevisionFromDocumentTree
(
doctree
);
prev_rev
=
revs_info
[
0
].
rev
;
prev_rev
=
revs_info
[
0
].
rev
;
}
else
{
}
else
{
revs_info
=
revs_info
=
priv
.
getRevisionFromDocumentTree
(
doctree
,
prev_rev
);
priv
.
getRevisionFromDocumentTree
(
doctree
,
prev_rev
);
}
}
f
.
getDocument
(
command
.
getDocId
()
+
"
.
"
+
prev_rev
,
f
.
getDocument
(
command
.
getDocId
()
+
"
.
"
+
prev_rev
,
command
.
getAttachmentId
());
command
.
getAttachmentId
());
},
function
(
err
)
{
},
switch
(
err
.
status
)
{
function
(
err
)
{
switch
(
err
.
status
)
{
case
404
:
case
404
:
that
.
error
(
err
);
that
.
error
(
err
);
break
;
break
;
...
@@ -595,11 +609,12 @@ jIO.addStorageType('revision', function (spec, my) {
...
@@ -595,11 +609,12 @@ jIO.addStorageType('revision', function (spec, my) {
if
(
response
.
_attachments
!==
undefined
)
{
if
(
response
.
_attachments
!==
undefined
)
{
attmt
=
response
.
_attachments
[
attmtid
];
attmt
=
response
.
_attachments
[
attmtid
];
if
(
attmt
!==
undefined
)
{
if
(
attmt
!==
undefined
)
{
prev_rev
=
prev_rev
=
priv
.
getRevisionFromPosition
(
priv
.
getRevisionFromPosition
(
revs_info
,
revs_info
,
attmt
.
revpos
);
attmt
.
revpos
f
.
getDocument
(
command
.
getDocId
()
+
"
.
"
+
);
prev_rev
+
"
/
"
+
attmtid
);
f
.
getDocument
(
command
.
getDocId
()
+
"
.
"
+
prev_rev
+
"
/
"
+
attmtid
);
return
;
return
;
}
}
}
}
...
@@ -615,30 +630,31 @@ jIO.addStorageType('revision', function (spec, my) {
...
@@ -615,30 +630,31 @@ jIO.addStorageType('revision', function (spec, my) {
response
.
_id
=
command
.
getDocId
();
response
.
_id
=
command
.
getDocId
();
response
.
_rev
=
prev_rev
;
response
.
_rev
=
prev_rev
;
if
(
command
.
getOption
(
"
revs
"
)
===
true
)
{
if
(
command
.
getOption
(
"
revs
"
)
===
true
)
{
response
.
_revisions
=
response
.
_revisions
=
priv
.
revsInfoToHistory
(
revs_info
);
priv
.
revsInfoToHistory
(
revs_info
);
}
}
if
(
command
.
getOption
(
"
revs_info
"
)
===
true
)
{
if
(
command
.
getOption
(
"
revs_info
"
)
===
true
)
{
response
.
_revs_info
=
revs_info
;
response
.
_revs_info
=
revs_info
;
}
}
if
(
command
.
getOption
(
"
conflicts
"
)
===
true
)
{
if
(
command
.
getOption
(
"
conflicts
"
)
===
true
)
{
response
.
_conflicts
=
response
.
_conflicts
=
priv
.
getLeavesFromDocumentTree
(
priv
.
getLeavesFromDocumentTree
(
doctree
,
doctree
,
prev_rev
);
prev_rev
);
if
(
response
.
_conflicts
.
length
===
0
)
{
if
(
response
.
_conflicts
.
length
===
0
)
{
delete
response
.
_conflicts
;
delete
response
.
_conflicts
;
}
}
}
}
}
}
that
.
success
(
response
);
that
.
success
(
response
);
},
function
(
err
)
{
},
function
(
err
)
{
that
.
error
(
err
);
that
.
error
(
err
);
}
}
);
);
};
};
if
(
command
.
getAttachmentId
()
&&
prev_rev
!==
undefined
)
{
if
(
command
.
getAttachmentId
()
&&
prev_rev
!==
undefined
)
{
f
.
getDocument
(
command
.
getDocId
()
+
"
.
"
+
prev_rev
+
f
.
getDocument
(
command
.
getDocId
()
+
"
.
"
+
prev_rev
+
"
/
"
+
command
.
getAttachmentId
());
"
/
"
+
command
.
getAttachmentId
());
}
else
{
}
else
{
f
.
getDocumentTree
();
f
.
getDocumentTree
();
}
}
...
@@ -652,43 +668,44 @@ jIO.addStorageType('revision', function (spec, my) {
...
@@ -652,43 +668,44 @@ jIO.addStorageType('revision', function (spec, my) {
* @param {object} command The JIO command
* @param {object} command The JIO command
*/
*/
that
.
remove
=
function
(
command
)
{
that
.
remove
=
function
(
command
)
{
var
f
=
{},
del_rev
,
option
,
new_doc
,
revs_info
,
new_id
;
var
f
=
{},
del_rev
,
option
,
new_doc
,
revs_info
;
option
=
command
.
cloneOption
();
option
=
command
.
cloneOption
();
if
(
option
[
"
max_retry
"
]
===
0
)
{
if
(
option
.
max_retry
===
0
)
{
option
[
"
max_retry
"
]
=
3
;
option
.
max_retry
=
3
;
}
}
del_rev
=
command
.
getDoc
().
_rev
;
del_rev
=
command
.
getDoc
().
_rev
;
f
.
removeDocument
=
function
(
docid
,
doctree
)
{
f
.
removeDocument
=
function
(
docid
,
doctree
)
{
if
(
command
.
getOption
(
"
keep_revision_history
"
)
!==
true
)
{
if
(
command
.
getOption
(
"
keep_revision_history
"
)
!==
true
)
{
if
(
command
.
getAttachmentId
()
===
undefined
)
{
if
(
command
.
getAttachmentId
()
===
undefined
)
{
// update tree
// update tree
revs_info
=
priv
.
postToDocumentTree
(
doctree
,
revs_info
=
priv
.
postToDocumentTree
(
command
.
getDoc
(),
true
);
doctree
,
command
.
getDoc
(),
true
);
// remove revision
// remove revision
that
.
addJob
(
that
.
addJob
(
"
remove
"
,
"
remove
"
,
priv
.
substorage
,
priv
.
substorage
,
docid
,
docid
,
option
,
option
,
function
(
response
)
{
function
(
)
{
// put tree
// put tree
doctree
.
_id
=
command
.
getDocId
()
+
doctree
.
_id
=
command
.
getDocId
()
+
priv
.
doctree_suffix
;
priv
.
doctree_suffix
;
that
.
addJob
(
that
.
addJob
(
"
put
"
,
"
put
"
,
priv
.
substorage
,
priv
.
substorage
,
doctree
,
doctree
,
command
.
cloneOption
(),
command
.
cloneOption
(),
function
(
response
)
{
function
(
)
{
that
.
success
({
that
.
success
({
"
ok
"
:
true
,
"
ok
"
:
true
,
"
id
"
:
command
.
getDocId
(),
"
id
"
:
command
.
getDocId
(),
"
rev
"
:
revs_info
[
0
].
rev
"
rev
"
:
revs_info
[
0
].
rev
});
});
},
},
function
(
err
)
{
function
()
{
that
.
error
({
that
.
error
({
"
status
"
:
409
,
"
status
"
:
409
,
"
statusText
"
:
"
Conflict
"
,
"
statusText
"
:
"
Conflict
"
,
...
@@ -700,7 +717,7 @@ jIO.addStorageType('revision', function (spec, my) {
...
@@ -700,7 +717,7 @@ jIO.addStorageType('revision', function (spec, my) {
}
}
);
);
},
},
function
(
err
)
{
function
(
)
{
that
.
error
({
that
.
error
({
"
status
"
:
404
,
"
status
"
:
404
,
"
statusText
"
:
"
Not Found
"
,
"
statusText
"
:
"
Not Found
"
,
...
@@ -716,16 +733,14 @@ jIO.addStorageType('revision', function (spec, my) {
...
@@ -716,16 +733,14 @@ jIO.addStorageType('revision', function (spec, my) {
that
.
addJob
(
that
.
addJob
(
"
get
"
,
"
get
"
,
priv
.
substorage
,
priv
.
substorage
,
command
.
getDocId
()
+
"
.
"
+
del_rev
,
command
.
getDocId
()
+
"
.
"
+
del_rev
,
option
,
option
,
function
(
response
)
{
function
(
response
)
{
// update tree
// update tree
revs_info
=
priv
.
postToDocumentTree
(
doctree
,
revs_info
=
priv
.
postToDocumentTree
(
doctree
,
command
.
getDoc
());
command
.
getDoc
());
new_doc
=
response
;
new_doc
=
response
;
delete
new_doc
.
_attachments
;
delete
new_doc
.
_attachments
;
new_doc
.
_id
=
new_doc
.
_id
+
"
.
"
+
revs_info
[
0
].
rev
;
new_doc
.
_id
=
new_doc
.
_id
+
"
.
"
+
revs_info
[
0
].
rev
;
// post new document version
// post new document version
that
.
addJob
(
that
.
addJob
(
...
@@ -733,21 +748,19 @@ jIO.addStorageType('revision', function (spec, my) {
...
@@ -733,21 +748,19 @@ jIO.addStorageType('revision', function (spec, my) {
priv
.
substorage
,
priv
.
substorage
,
new_doc
,
new_doc
,
command
.
cloneOption
(),
command
.
cloneOption
(),
function
(
response
)
{
function
()
{
// put tree
// put tree
doctree
.
_id
=
command
.
getDocId
()
+
doctree
.
_id
=
command
.
getDocId
()
+
priv
.
doctree_suffix
;
priv
.
doctree_suffix
;
that
.
addJob
(
that
.
addJob
(
"
put
"
,
"
put
"
,
priv
.
substorage
,
priv
.
substorage
,
doctree
,
doctree
,
command
.
cloneOption
(),
command
.
cloneOption
(),
function
(
response
)
{
function
(
)
{
that
.
success
({
that
.
success
({
"
ok
"
:
true
,
"
ok
"
:
true
,
"
id
"
:
new_doc
.
_id
,
"
id
"
:
new_doc
.
_id
,
"
rev
"
:
revs_info
[
0
].
rev
"
rev
"
:
revs_info
[
0
].
rev
});
});
},
},
function
(
err
)
{
function
(
err
)
{
...
@@ -756,9 +769,8 @@ jIO.addStorageType('revision', function (spec, my) {
...
@@ -756,9 +769,8 @@ jIO.addStorageType('revision', function (spec, my) {
that
.
error
(
err
);
that
.
error
(
err
);
}
}
);
);
},
},
function
(
err
)
{
function
()
{
that
.
error
({
that
.
error
({
"
status
"
:
409
,
"
status
"
:
409
,
"
statusText
"
:
"
Conflict
"
,
"
statusText
"
:
"
Conflict
"
,
...
@@ -770,7 +782,7 @@ jIO.addStorageType('revision', function (spec, my) {
...
@@ -770,7 +782,7 @@ jIO.addStorageType('revision', function (spec, my) {
}
}
);
);
},
},
function
(
err
)
{
function
(
)
{
that
.
error
({
that
.
error
({
"
status
"
:
404
,
"
status
"
:
404
,
"
statusText
"
:
"
Not Found
"
,
"
statusText
"
:
"
Not Found
"
,
...
@@ -782,8 +794,6 @@ jIO.addStorageType('revision', function (spec, my) {
...
@@ -782,8 +794,6 @@ jIO.addStorageType('revision', function (spec, my) {
}
}
);
);
}
}
}
else
{
// keep history = update document tree only
}
}
};
};
if
(
typeof
del_rev
===
"
string
"
)
{
if
(
typeof
del_rev
===
"
string
"
)
{
...
@@ -792,7 +802,7 @@ jIO.addStorageType('revision', function (spec, my) {
...
@@ -792,7 +802,7 @@ jIO.addStorageType('revision', function (spec, my) {
"
status
"
:
31
,
"
status
"
:
31
,
"
statusText
"
:
"
Wrong Revision Format
"
,
"
statusText
"
:
"
Wrong Revision Format
"
,
"
error
"
:
"
wrong_revision_format
"
,
"
error
"
:
"
wrong_revision_format
"
,
"
message
"
:
"
The document previous revision does not match
"
+
"
message
"
:
"
The document previous revision does not match
"
+
"
[0-9]+-[0-9a-zA-Z]+
"
,
"
[0-9]+-[0-9a-zA-Z]+
"
,
"
reason
"
:
"
Previous revision is wrong
"
"
reason
"
:
"
Previous revision is wrong
"
});
});
...
@@ -804,7 +814,7 @@ jIO.addStorageType('revision', function (spec, my) {
...
@@ -804,7 +814,7 @@ jIO.addStorageType('revision', function (spec, my) {
that
.
addJob
(
that
.
addJob
(
"
get
"
,
"
get
"
,
priv
.
substorage
,
priv
.
substorage
,
command
.
getDocId
()
+
priv
.
doctree_suffix
,
command
.
getDocId
()
+
priv
.
doctree_suffix
,
option
,
option
,
function
(
response
)
{
function
(
response
)
{
response
.
_conflicts
=
priv
.
getLeavesFromDocumentTree
(
response
);
response
.
_conflicts
=
priv
.
getLeavesFromDocumentTree
(
response
);
...
@@ -819,16 +829,15 @@ jIO.addStorageType('revision', function (spec, my) {
...
@@ -819,16 +829,15 @@ jIO.addStorageType('revision', function (spec, my) {
"
reason
"
:
"
Cannot delete a document without revision
"
"
reason
"
:
"
Cannot delete a document without revision
"
});
});
return
;
return
;
}
else
{
}
// revision provided
// revision provided
if
(
priv
.
isRevisionALeaf
(
response
,
del_rev
)
===
true
)
{
if
(
priv
.
isRevisionALeaf
(
response
,
del_rev
)
===
true
)
{
if
(
typeof
command
.
getAttachmentId
()
===
"
string
"
)
{
if
(
typeof
command
.
getAttachmentId
()
===
"
string
"
)
{
f
.
removeDocument
(
command
.
getDocId
()
+
"
.
"
+
del_rev
+
f
.
removeDocument
(
command
.
getDocId
()
+
"
.
"
+
del_rev
+
"
/
"
+
command
.
getAttachmentId
(),
response
);
"
/
"
+
command
.
getAttachmentId
(),
response
);
}
else
{
}
else
{
f
.
removeDocument
(
command
.
getDocId
()
+
"
.
"
+
del_rev
,
f
.
removeDocument
(
command
.
getDocId
()
+
"
.
"
+
del_rev
,
response
response
);
);
}
}
}
else
{
}
else
{
that
.
error
({
that
.
error
({
...
@@ -840,9 +849,8 @@ jIO.addStorageType('revision', function (spec, my) {
...
@@ -840,9 +849,8 @@ jIO.addStorageType('revision', function (spec, my) {
});
});
return
;
return
;
}
}
}
},
},
function
(
err
)
{
function
(
)
{
that
.
error
({
that
.
error
({
"
status
"
:
404
,
"
status
"
:
404
,
"
statusText
"
:
"
Not Found
"
,
"
statusText
"
:
"
Not Found
"
,
...
@@ -860,7 +868,7 @@ jIO.addStorageType('revision', function (spec, my) {
...
@@ -860,7 +868,7 @@ jIO.addStorageType('revision', function (spec, my) {
* @method allDocs
* @method allDocs
* @param {object} command The JIO command
* @param {object} command The JIO command
*/
*/
that
.
allDocs
=
function
(
command
)
{
that
.
allDocs
=
function
(
)
{
setTimeout
(
function
()
{
setTimeout
(
function
()
{
that
.
error
({
that
.
error
({
"
status
"
:
405
,
"
status
"
:
405
,
...
...
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