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
Kirill Smelkov
jio
Commits
14aa39ea
Commit
14aa39ea
authored
Jan 10, 2013
by
Sven Franck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
jslint pass command.js (2indent)
parent
fbdf009d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
283 additions
and
289 deletions
+283
-289
src/jio/commands/command.js
src/jio/commands/command.js
+283
-289
No files found.
src/jio/commands/command.js
View file @
14aa39ea
var
command
=
function
(
spec
,
my
)
{
// -*- jslint: --nomen --todo --maxlen 80 -*-
var
that
=
{};
var
command
=
function
(
spec
,
my
)
{
var
that
=
{},
priv
=
{};
spec
=
spec
||
{};
spec
=
spec
||
{};
my
=
my
||
{};
my
=
my
||
{};
// Attributes //
var
priv
=
{};
priv
.
commandlist
=
{
priv
.
commandlist
=
{
'
post
'
:
postCommand
,
'
post
'
:
postCommand
,
'
put
'
:
putCommand
,
'
put
'
:
putCommand
,
'
get
'
:
getCommand
,
'
get
'
:
getCommand
,
'
remove
'
:
removeCommand
,
'
remove
'
:
removeCommand
,
'
allDocs
'
:
allDocsCommand
,
'
allDocs
'
:
allDocsCommand
,
'
putAttachment
'
:
putAttachmentCommand
'
putAttachment
'
:
putAttachmentCommand
};
};
// creates the good command thanks to his label
// creates the good command thanks to his label
if
(
spec
.
label
&&
priv
.
commandlist
[
spec
.
label
])
{
if
(
spec
.
label
&&
priv
.
commandlist
[
spec
.
label
])
{
...
@@ -22,20 +24,25 @@ var command = function(spec, my) {
...
@@ -22,20 +24,25 @@ var command = function(spec, my) {
priv
.
tried
=
0
;
priv
.
tried
=
0
;
priv
.
doc
=
spec
.
doc
||
{};
priv
.
doc
=
spec
.
doc
||
{};
if
(
typeof
priv
.
doc
!==
"
object
"
)
{
if
(
typeof
priv
.
doc
!==
"
object
"
)
{
priv
.
doc
=
{
"
_id
"
:
priv
.
doc
.
toString
()};
priv
.
doc
=
{
"
_id
"
:
priv
.
doc
.
toString
()
};
}
}
priv
.
docid
=
spec
.
docid
||
priv
.
doc
.
_id
;
priv
.
docid
=
spec
.
docid
||
priv
.
doc
.
_id
;
priv
.
option
=
spec
.
options
||
{};
priv
.
option
=
spec
.
options
||
{};
priv
.
callbacks
=
spec
.
callbacks
||
{};
priv
.
callbacks
=
spec
.
callbacks
||
{};
priv
.
success
=
priv
.
callbacks
.
success
||
function
()
{};
priv
.
success
=
priv
.
callbacks
.
success
||
function
()
{};
priv
.
error
=
priv
.
callbacks
.
error
||
function
()
{};
priv
.
error
=
priv
.
callbacks
.
error
||
function
()
{};
priv
.
retry
=
function
()
{
priv
.
retry
=
function
()
{
that
.
error
({
that
.
error
({
status
:
13
,
statusText
:
'
Fail Retry
'
,
error
:
'
fail_retry
'
,
status
:
13
,
message
:
'
Impossible to retry.
'
,
reason
:
'
Impossible to retry.
'
statusText
:
'
Fail Retry
'
,
error
:
'
fail_retry
'
,
message
:
'
Impossible to retry.
'
,
reason
:
'
Impossible to retry.
'
});
});
};
};
priv
.
end
=
function
()
{};
priv
.
end
=
function
()
{};
priv
.
on_going
=
false
;
priv
.
on_going
=
false
;
// Methods //
// Methods //
...
@@ -46,10 +53,10 @@ var command = function(spec, my) {
...
@@ -46,10 +53,10 @@ var command = function(spec, my) {
*/
*/
that
.
serialized
=
function
()
{
that
.
serialized
=
function
()
{
var
o
=
{};
var
o
=
{};
o
[
"
label
"
]
=
that
.
getLabel
();
o
.
label
=
that
.
getLabel
();
o
[
"
tried
"
]
=
priv
.
tried
;
o
.
tried
=
priv
.
tried
;
o
[
"
doc
"
]
=
that
.
cloneDoc
();
o
.
doc
=
that
.
cloneDoc
();
o
[
"
option
"
]
=
that
.
cloneOption
();
o
.
option
=
that
.
cloneOption
();
return
o
;
return
o
;
};
};
...
@@ -58,7 +65,7 @@ var command = function(spec, my) {
...
@@ -58,7 +65,7 @@ var command = function(spec, my) {
* @method getLabel
* @method getLabel
* @return {string} The label.
* @return {string} The label.
*/
*/
that
.
getLabel
=
function
()
{
that
.
getLabel
=
function
()
{
return
'
command
'
;
return
'
command
'
;
};
};
...
@@ -91,7 +98,7 @@ var command = function(spec, my) {
...
@@ -91,7 +98,7 @@ var command = function(spec, my) {
* @method getDoc
* @method getDoc
* @return {object} The document.
* @return {object} The document.
*/
*/
that
.
getDoc
=
function
()
{
that
.
getDoc
=
function
()
{
return
priv
.
doc
;
return
priv
.
doc
;
};
};
...
@@ -157,12 +164,13 @@ var command = function(spec, my) {
...
@@ -157,12 +164,13 @@ var command = function(spec, my) {
*/
*/
that
.
validate
=
function
(
storage
)
{
that
.
validate
=
function
(
storage
)
{
if
(
typeof
priv
.
docid
===
"
string
"
&&
if
(
typeof
priv
.
docid
===
"
string
"
&&
!
priv
.
docid
.
match
(
/^
[^\/]
+
([\/][^\/]
+
)?
$/
))
{
!
priv
.
docid
.
match
(
"
^[^
\
/]+([
\
/][^
\
/]+)?$
"
))
{
that
.
error
({
that
.
error
({
status
:
21
,
statusText
:
'
Invalid Document Id
'
,
status
:
21
,
error
:
'
invalid_document_id
'
,
statusText
:
'
Invalid Document Id
'
,
message
:
'
The document id must be like "abc" or "abc/def".
'
,
error
:
'
invalid_document_id
'
,
reason
:
'
The document id is no like "abc" or "abc/def"
'
message
:
'
The document id must be like "abc" or "abc/def".
'
,
reason
:
'
The document id is no like "abc" or "abc/def"
'
});
});
return
false
;
return
false
;
}
}
...
@@ -175,7 +183,7 @@ var command = function(spec, my) {
...
@@ -175,7 +183,7 @@ var command = function(spec, my) {
/*
/*
* Extend this function
* Extend this function
*/
*/
that
.
validateState
=
function
()
{
that
.
validateState
=
function
()
{
return
true
;
return
true
;
};
};
...
@@ -185,7 +193,7 @@ var command = function(spec, my) {
...
@@ -185,7 +193,7 @@ var command = function(spec, my) {
* @return {boolean} The result
* @return {boolean} The result
*/
*/
that
.
canBeRetried
=
function
()
{
that
.
canBeRetried
=
function
()
{
return
(
typeof
priv
.
option
.
max_retry
===
'
undefined
'
||
return
(
priv
.
option
.
max_retry
===
undefined
||
priv
.
option
.
max_retry
===
0
||
priv
.
option
.
max_retry
===
0
||
priv
.
tried
<
priv
.
option
.
max_retry
);
priv
.
tried
<
priv
.
option
.
max_retry
);
};
};
...
@@ -195,7 +203,7 @@ var command = function(spec, my) {
...
@@ -195,7 +203,7 @@ var command = function(spec, my) {
* @method getTried
* @method getTried
* @return {number} The number of time the command has been tried
* @return {number} The number of time the command has been tried
*/
*/
that
.
getTried
=
function
()
{
that
.
getTried
=
function
()
{
return
priv
.
tried
;
return
priv
.
tried
;
};
};
...
@@ -203,49 +211,43 @@ var command = function(spec, my) {
...
@@ -203,49 +211,43 @@ var command = function(spec, my) {
* Delegate actual excecution the storage.
* Delegate actual excecution the storage.
* @param {object} storage The storage.
* @param {object} storage The storage.
*/
*/
that
.
execute
=
function
(
storage
)
{
that
.
execute
=
function
(
storage
)
{
if
(
!
priv
.
on_going
)
{
if
(
!
priv
.
on_going
)
{
if
(
that
.
validate
(
storage
))
{
if
(
that
.
validate
(
storage
))
{
priv
.
tried
++
;
priv
.
tried
+=
1
;
priv
.
on_going
=
true
;
priv
.
on_going
=
true
;
storage
.
execute
(
that
);
storage
.
execute
(
that
);
}
}
}
}
};
};
/**
/**
* Execute the good method from the storage.
* Execute the good method from the storage.
* Override this function.
* Override this function.
* @method executeOn
* @method executeOn
* @param {object} storage The storage.
* @param {object} storage The storage.
*/
*/
that
.
executeOn
=
function
(
storage
)
{};
that
.
executeOn
=
function
(
storage
)
{};
that
.
success
=
function
(
return_value
)
{
that
.
success
=
function
(
return_value
)
{
priv
.
on_going
=
false
;
priv
.
on_going
=
false
;
priv
.
success
(
return_value
);
priv
.
success
(
return_value
);
priv
.
end
(
doneStatus
());
priv
.
end
(
doneStatus
());
};
};
that
.
retry
=
function
(
return_error
)
{
that
.
retry
=
function
(
return_error
)
{
priv
.
on_going
=
false
;
priv
.
on_going
=
false
;
if
(
that
.
canBeRetried
())
{
if
(
that
.
canBeRetried
())
{
priv
.
retry
();
priv
.
retry
();
}
else
{
}
else
{
that
.
error
(
return_error
);
that
.
error
(
return_error
);
}
}
};
};
that
.
error
=
function
(
return_error
)
{
that
.
error
=
function
(
return_error
)
{
priv
.
on_going
=
false
;
priv
.
on_going
=
false
;
priv
.
error
(
return_error
);
priv
.
error
(
return_error
);
priv
.
end
(
failStatus
());
priv
.
end
(
failStatus
());
};
};
that
.
end
=
function
()
{
that
.
end
=
function
()
{
priv
.
end
(
doneStatus
());
priv
.
end
(
doneStatus
());
};
};
that
.
onSuccessDo
=
function
(
fun
)
{
that
.
onSuccessDo
=
function
(
fun
)
{
if
(
fun
)
{
if
(
fun
)
{
priv
.
success
=
fun
;
priv
.
success
=
fun
;
...
@@ -253,7 +255,6 @@ var command = function(spec, my) {
...
@@ -253,7 +255,6 @@ var command = function(spec, my) {
return
priv
.
success
;
return
priv
.
success
;
}
}
};
};
that
.
onErrorDo
=
function
(
fun
)
{
that
.
onErrorDo
=
function
(
fun
)
{
if
(
fun
)
{
if
(
fun
)
{
priv
.
error
=
fun
;
priv
.
error
=
fun
;
...
@@ -261,24 +262,20 @@ var command = function(spec, my) {
...
@@ -261,24 +262,20 @@ var command = function(spec, my) {
return
priv
.
error
;
return
priv
.
error
;
}
}
};
};
that
.
onEndDo
=
function
(
fun
)
{
that
.
onEndDo
=
function
(
fun
)
{
priv
.
end
=
fun
;
priv
.
end
=
fun
;
};
};
that
.
onRetryDo
=
function
(
fun
)
{
that
.
onRetryDo
=
function
(
fun
)
{
priv
.
retry
=
fun
;
priv
.
retry
=
fun
;
};
};
/**
/**
* Is the command can be restored by another JIO : yes.
* Is the command can be restored by another JIO : yes.
* @method canBeRestored
* @method canBeRestored
* @return {boolean} true
* @return {boolean} true
*/
*/
that
.
canBeRestored
=
function
()
{
that
.
canBeRestored
=
function
()
{
return
true
;
return
true
;
};
};
/**
/**
* Clones the command and returns it.
* Clones the command and returns it.
* @method clone
* @method clone
...
@@ -287,7 +284,6 @@ var command = function(spec, my) {
...
@@ -287,7 +284,6 @@ var command = function(spec, my) {
that
.
clone
=
function
()
{
that
.
clone
=
function
()
{
return
command
(
that
.
serialized
(),
my
);
return
command
(
that
.
serialized
(),
my
);
};
};
/**
/**
* Clones the command options and returns the clone version.
* Clones the command options and returns the clone version.
* @method cloneOption
* @method cloneOption
...
@@ -296,7 +292,6 @@ var command = function(spec, my) {
...
@@ -296,7 +292,6 @@ var command = function(spec, my) {
that
.
cloneOption
=
function
()
{
that
.
cloneOption
=
function
()
{
return
JSON
.
parse
(
JSON
.
stringify
(
priv
.
option
));
return
JSON
.
parse
(
JSON
.
stringify
(
priv
.
option
));
};
};
/**
/**
* Clones the document and returns the clone version.
* Clones the document and returns the clone version.
* @method cloneDoc
* @method cloneDoc
...
@@ -305,6 +300,5 @@ var command = function(spec, my) {
...
@@ -305,6 +300,5 @@ var command = function(spec, my) {
that
.
cloneDoc
=
function
()
{
that
.
cloneDoc
=
function
()
{
return
JSON
.
parse
(
JSON
.
stringify
(
priv
.
doc
));
return
JSON
.
parse
(
JSON
.
stringify
(
priv
.
doc
));
};
};
return
that
;
return
that
;
};
};
\ No newline at end of file
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