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
3e152964
Commit
3e152964
authored
Sep 27, 2013
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
promy replaced by RSVP library
parent
78fe0cd7
Changes
11
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
265 additions
and
1009 deletions
+265
-1009
Gruntfile.js
Gruntfile.js
+0
-10
src/jio/core/restCommandRejecter.js
src/jio/core/restCommandRejecter.js
+69
-0
src/jio/core/restCommandResolver.js
src/jio/core/restCommandResolver.js
+80
-0
src/jio/core/util.js
src/jio/core/util.js
+51
-38
src/jio/features/jobChecker.js
src/jio/features/jobChecker.js
+13
-11
src/jio/features/jobExecuter.js
src/jio/features/jobExecuter.js
+8
-21
src/jio/features/jobMaker.js
src/jio/features/jobMaker.js
+1
-1
src/jio/features/restApi.js
src/jio/features/restApi.js
+28
-16
src/jio/features/restParamChecker.js
src/jio/features/restParamChecker.js
+11
-11
src/jio/intro.js
src/jio/intro.js
+4
-4
src/promy/promy.js
src/promy/promy.js
+0
-897
No files found.
Gruntfile.js
View file @
3e152964
...
@@ -14,12 +14,6 @@ module.exports = function (grunt) {
...
@@ -14,12 +14,6 @@ module.exports = function (grunt) {
errorsOnly
:
true
errorsOnly
:
true
}
}
},
},
promy
:
{
src
:
[
'
src/promy/**/*.js
'
],
options
:
{
errorsOnly
:
true
}
},
jio
:
{
jio
:
{
src
:
[
'
src/jio/**/*.js
'
],
src
:
[
'
src/jio/**/*.js
'
],
exclude
:
[
'
src/jio/intro.js
'
,
'
src/jio/outro.js
'
],
exclude
:
[
'
src/jio/intro.js
'
,
'
src/jio/outro.js
'
],
...
@@ -84,10 +78,6 @@ module.exports = function (grunt) {
...
@@ -84,10 +78,6 @@ module.exports = function (grunt) {
banner
:
'
/*! <%= pkg.name %> <%= pkg.version %>
'
+
banner
:
'
/*! <%= pkg.name %> <%= pkg.version %>
'
+
'
<%= grunt.template.today("yyyy-mm-dd") %> */
\n
'
'
<%= grunt.template.today("yyyy-mm-dd") %> */
\n
'
},
},
promy
:
{
src
:
'
src/promy/promy.js
'
,
dest
:
'
promy.min.js
'
},
jio
:
{
jio
:
{
src
:
'
jio.js
'
,
// '<%= pkg.name %>.js'
src
:
'
jio.js
'
,
// '<%= pkg.name %>.js'
dest
:
'
jio.min.js
'
dest
:
'
jio.min.js
'
...
...
src/jio/core/restCommandRejecter.js
0 → 100644
View file @
3e152964
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true, regexp: true */
/*global constants, dictUpdate, deepClone */
function
restCommandRejecter
(
param
,
args
)
{
// reject(status, reason, message, {"custom": "value"});
// reject(status, reason, {..});
// reject(status, {..});
var
a
=
args
[
0
],
b
=
args
[
1
],
c
=
args
[
2
],
d
=
args
[
3
],
weak
,
strong
;
weak
=
{
"
result
"
:
"
error
"
};
strong
=
{};
weak
.
status
=
constants
.
http_status
.
unknown
;
weak
.
statusText
=
constants
.
http_status_text
.
unknown
;
weak
.
message
=
'
Command failed
'
;
weak
.
reason
=
'
fail
'
;
weak
.
method
=
param
.
method
;
if
(
param
.
kwargs
.
_id
)
{
weak
.
id
=
param
.
kwargs
.
_id
;
}
if
(
/Attachment$/
.
test
(
param
.
method
))
{
weak
.
attachment
=
param
.
kwargs
.
_attachment
;
}
if
(
typeof
a
!==
'
object
'
||
Array
.
isArray
(
a
))
{
strong
.
status
=
constants
.
http_status
[
a
];
strong
.
statusText
=
constants
.
http_status_text
[
a
];
if
(
strong
.
status
===
undefined
||
strong
.
statusText
===
undefined
)
{
return
restCommandRejecter
(
param
,
[
// can create infernal loop if 'internal_storage_error' is not defined
// in the constants
'
internal_storage_error
'
,
'
invalid response
'
,
'
Unknown status "
'
+
a
+
'
"
'
]);
}
a
=
b
;
b
=
c
;
c
=
d
;
}
if
(
typeof
a
!==
'
object
'
||
Array
.
isArray
(
a
))
{
strong
.
reason
=
a
;
a
=
b
;
b
=
c
;
}
if
(
typeof
a
!==
'
object
'
||
Array
.
isArray
(
a
))
{
strong
.
message
=
a
;
a
=
b
;
}
if
(
typeof
a
===
'
object
'
&&
!
Array
.
isArray
(
a
))
{
dictUpdate
(
weak
,
a
);
}
dictUpdate
(
weak
,
strong
);
strong
=
undefined
;
if
(
weak
.
error
===
undefined
)
{
weak
.
error
=
weak
.
statusText
.
toLowerCase
().
replace
(
/ /g
,
'
_
'
).
replace
(
/
[^
_a-z
]
/g
,
''
);
}
if
(
typeof
weak
.
message
!==
'
string
'
)
{
weak
.
message
=
""
;
}
if
(
typeof
weak
.
reason
!==
'
string
'
)
{
weak
.
reason
=
"
unknown
"
;
}
return
param
.
solver
.
reject
(
deepClone
(
weak
));
}
src/jio/core/
IODeferred
.js
→
src/jio/core/
restCommandResolver
.js
View file @
3e152964
/*jslint indent: 2, maxlen: 80,
nomen: true, sloppy: true, regexp
: true */
/*jslint indent: 2, maxlen: 80,
sloppy: true, nomen
: true */
/*global
Deferred, inherits, constants, dictUpdate, deepClone, Blob
,
/*global
constants, methodType, dictUpdate, Blob, deepClone
,
methodType
*/
restCommandRejecter
*/
function
IODeferred
(
method
,
info
)
{
function
restCommandResolver
(
param
,
args
)
{
IODeferred
.
super_
.
call
(
this
);
this
.
_info
=
info
||
{};
this
.
_method
=
method
;
// this._options = options;
}
inherits
(
IODeferred
,
Deferred
);
IODeferred
.
prototype
.
resolve
=
function
(
a
,
b
)
{
// resolve('ok', {"custom": "value"});
// resolve('ok', {"custom": "value"});
// resolve(200, {...});
// resolve(200, {...});
// resolve({...});
// resolve({...});
var
weak
=
{
"
result
"
:
"
success
"
},
strong
=
{};
var
a
=
args
[
0
],
b
=
args
[
1
],
weak
=
{
"
result
"
:
"
success
"
},
strong
=
{};
if
(
this
.
_
method
===
'
post
'
)
{
if
(
param
.
method
===
'
post
'
)
{
weak
.
status
=
constants
.
http_status
.
created
;
weak
.
status
=
constants
.
http_status
.
created
;
weak
.
statusText
=
constants
.
http_status_text
.
created
;
weak
.
statusText
=
constants
.
http_status_text
.
created
;
}
else
if
(
methodType
(
this
.
_
method
)
===
"
writer
"
||
}
else
if
(
methodType
(
param
.
method
)
===
"
writer
"
||
this
.
_
method
===
"
check
"
)
{
param
.
method
===
"
check
"
)
{
weak
.
status
=
constants
.
http_status
.
no_content
;
weak
.
status
=
constants
.
http_status
.
no_content
;
weak
.
statusText
=
constants
.
http_status_text
.
no_content
;
weak
.
statusText
=
constants
.
http_status_text
.
no_content
;
}
else
{
}
else
{
weak
.
status
=
constants
.
http_status
.
ok
;
weak
.
status
=
constants
.
http_status
.
ok
;
weak
.
statusText
=
constants
.
http_status_text
.
ok
;
weak
.
statusText
=
constants
.
http_status_text
.
ok
;
}
}
if
(
this
.
_info
.
_id
)
{
if
(
param
.
kwargs
.
_id
)
{
weak
.
id
=
this
.
_info
.
_id
;
weak
.
id
=
param
.
kwargs
.
_id
;
}
}
if
(
/Attachment$/
.
test
(
this
.
_
method
))
{
if
(
/Attachment$/
.
test
(
param
.
method
))
{
weak
.
attachment
=
this
.
_info
.
_attachment
;
weak
.
attachment
=
param
.
kwargs
.
_attachment
;
}
}
weak
.
method
=
this
.
_
method
;
weak
.
method
=
param
.
method
;
if
(
typeof
a
===
'
string
'
||
(
typeof
a
===
'
number
'
&&
isFinite
(
a
)))
{
if
(
typeof
a
===
'
string
'
||
(
typeof
a
===
'
number
'
&&
isFinite
(
a
)))
{
strong
.
status
=
constants
.
http_status
[
a
];
strong
.
status
=
constants
.
http_status
[
a
];
strong
.
statusText
=
constants
.
http_status_text
[
a
];
strong
.
statusText
=
constants
.
http_status_text
[
a
];
if
(
strong
.
status
===
undefined
||
if
(
strong
.
status
===
undefined
||
strong
.
statusText
===
undefined
)
{
strong
.
statusText
===
undefined
)
{
return
this
.
reject
(
return
restCommandRejecter
(
param
,
[
'
internal_storage_error
'
,
'
internal_storage_error
'
,
'
invalid response
'
,
'
invalid response
'
,
'
Unknown status "
'
+
a
+
'
"
'
'
Unknown status "
'
+
a
+
'
"
'
);
]
);
}
}
a
=
b
;
a
=
b
;
}
}
...
@@ -52,14 +44,14 @@ IODeferred.prototype.resolve = function (a, b) {
...
@@ -52,14 +44,14 @@ IODeferred.prototype.resolve = function (a, b) {
}
}
dictUpdate
(
weak
,
strong
);
dictUpdate
(
weak
,
strong
);
strong
=
undefined
;
// free memory
strong
=
undefined
;
// free memory
if
(
this
.
_
method
===
'
post
'
&&
(
typeof
weak
.
id
!==
'
string
'
||
!
weak
.
id
))
{
if
(
param
.
method
===
'
post
'
&&
(
typeof
weak
.
id
!==
'
string
'
||
!
weak
.
id
))
{
return
this
.
reject
(
return
restCommandRejecter
(
param
,
[
'
internal_storage_error
'
,
'
internal_storage_error
'
,
'
invalid response
'
,
'
invalid response
'
,
'
New document id have to be specified
'
'
New document id have to be specified
'
);
]
);
}
}
if
(
this
.
_
method
===
'
getAttachment
'
)
{
if
(
param
.
method
===
'
getAttachment
'
)
{
if
(
typeof
weak
.
data
===
'
string
'
)
{
if
(
typeof
weak
.
data
===
'
string
'
)
{
weak
.
data
=
new
Blob
([
weak
.
data
],
{
weak
.
data
=
new
Blob
([
weak
.
data
],
{
"
type
"
:
weak
.
content_type
||
weak
.
mimetype
||
""
"
type
"
:
weak
.
content_type
||
weak
.
mimetype
||
""
...
@@ -68,111 +60,21 @@ IODeferred.prototype.resolve = function (a, b) {
...
@@ -68,111 +60,21 @@ IODeferred.prototype.resolve = function (a, b) {
delete
weak
.
mimetype
;
delete
weak
.
mimetype
;
}
}
if
(
!
(
weak
.
data
instanceof
Blob
))
{
if
(
!
(
weak
.
data
instanceof
Blob
))
{
return
this
.
reject
(
return
restCommandRejecter
(
param
,
[
'
internal_storage_error
'
,
'
internal_storage_error
'
,
'
invalid response
'
,
'
invalid response
'
,
'
getAttachment method needs a Blob as returned "data".
'
'
getAttachment method needs a Blob as returned "data".
'
);
]
);
}
}
}
else
if
(
methodType
(
this
.
_
method
)
===
'
reader
'
&&
}
else
if
(
methodType
(
param
.
method
)
===
'
reader
'
&&
this
.
_
method
!==
'
check
'
&&
param
.
method
!==
'
check
'
&&
(
typeof
weak
.
data
!==
'
object
'
||
(
typeof
weak
.
data
!==
'
object
'
||
Object
.
getPrototypeOf
(
weak
.
data
)
!==
Object
.
prototype
))
{
Object
.
getPrototypeOf
(
weak
.
data
)
!==
Object
.
prototype
))
{
return
this
.
reject
(
return
restCommandRejecter
(
param
,
[
'
internal_storage_error
'
,
'
internal_storage_error
'
,
'
invalid response
'
,
'
invalid response
'
,
this
.
_method
+
'
method needs a dict as returned "data".
'
param
.
method
+
'
method needs a dict as returned "data".
'
);
]);
}
//return super_resolve(deepClone(weak));
return
IODeferred
.
super_
.
prototype
.
resolve
.
call
(
this
,
deepClone
(
weak
));
};
IODeferred
.
prototype
.
reject
=
function
(
a
,
b
,
c
,
d
)
{
// reject(status, reason, message, {"custom": "value"});
// reject(status, reason, {..});
// reject(status, {..});
var
weak
=
{
"
result
"
:
"
error
"
},
strong
=
{};
weak
.
status
=
constants
.
http_status
.
unknown
;
weak
.
statusText
=
constants
.
http_status_text
.
unknown
;
weak
.
message
=
'
Command failed
'
;
weak
.
reason
=
'
fail
'
;
weak
.
method
=
this
.
_method
;
if
(
this
.
_info
.
_id
)
{
weak
.
id
=
this
.
_info
.
_id
;
}
if
(
/Attachment$/
.
test
(
this
.
_method
))
{
weak
.
attachment
=
this
.
_info
.
_attachment
;
}
if
(
typeof
a
!==
'
object
'
||
Array
.
isArray
(
a
))
{
strong
.
status
=
constants
.
http_status
[
a
];
strong
.
statusText
=
constants
.
http_status_text
[
a
];
if
(
strong
.
status
===
undefined
||
strong
.
statusText
===
undefined
)
{
return
this
.
reject
(
// can create infernal loop if 'internal_storage_error' is not defined
// in the constants
'
internal_storage_error
'
,
'
invalid response
'
,
'
Unknown status "
'
+
a
+
'
"
'
);
}
a
=
b
;
b
=
c
;
c
=
d
;
}
if
(
typeof
a
!==
'
object
'
||
Array
.
isArray
(
a
))
{
strong
.
reason
=
a
;
a
=
b
;
b
=
c
;
}
if
(
typeof
a
!==
'
object
'
||
Array
.
isArray
(
a
))
{
strong
.
message
=
a
;
a
=
b
;
}
if
(
typeof
a
===
'
object
'
&&
!
Array
.
isArray
(
a
))
{
dictUpdate
(
weak
,
a
);
}
}
return
param
.
solver
.
resolve
(
deepClone
(
weak
));
dictUpdate
(
weak
,
strong
);
}
strong
=
undefined
;
if
(
weak
.
error
===
undefined
)
{
weak
.
error
=
weak
.
statusText
.
toLowerCase
().
replace
(
/ /g
,
'
_
'
).
replace
(
/
[^
_a-z
]
/g
,
''
);
}
if
(
typeof
weak
.
message
!==
'
string
'
)
{
weak
.
message
=
""
;
}
if
(
typeof
weak
.
reason
!==
'
string
'
)
{
weak
.
reason
=
"
unknown
"
;
}
//return super_reject(deepClone(weak));
return
IODeferred
.
super_
.
prototype
.
reject
.
call
(
this
,
deepClone
(
weak
));
};
IODeferred
.
createFromDeferred
=
function
(
method
,
info
,
options
,
deferred
)
{
var
iodeferred
=
new
IODeferred
(
method
,
info
,
options
);
// iodeferred.promise().done(deferred.resolve.bind(deferred)).
// fail(deferred.reject.bind(deferred)).
// progress(deferred.notify.bind(deferred));
// // phantomjs doesn't like 'bind'...
iodeferred
.
promise
.
then
(
deferred
.
resolve
.
bind
(
deferred
),
deferred
.
reject
.
bind
(
deferred
),
deferred
.
notify
.
bind
(
deferred
)
);
return
iodeferred
;
};
IODeferred
.
createFromParam
=
function
(
param
)
{
return
IODeferred
.
createFromDeferred
(
param
.
method
,
param
.
kwargs
,
param
.
options
,
param
.
deferred
);
};
src/jio/core/util.js
View file @
3e152964
/*jslint indent: 2, maxlen: 80, nomen: true, sloppy: true */
/*jslint indent: 2, maxlen: 80, nomen: true, sloppy: true */
/*global exports, Blob, FileReader,
Deferred
, hex_sha256, XMLHttpRequest,
/*global exports, Blob, FileReader,
RSVP
, hex_sha256, XMLHttpRequest,
constants */
constants */
/**
/**
...
@@ -310,32 +310,41 @@ function makeBinaryStringDigest(string) {
...
@@ -310,32 +310,41 @@ function makeBinaryStringDigest(string) {
exports
.
util
.
makeBinaryStringDigest
=
makeBinaryStringDigest
;
exports
.
util
.
makeBinaryStringDigest
=
makeBinaryStringDigest
;
function
readBlobAsBinaryString
(
blob
)
{
function
readBlobAsBinaryString
(
blob
)
{
var
deferred
=
new
Deferred
(),
fr
=
new
FileReader
();
var
fr
=
new
FileReader
();
fr
.
addEventListener
(
"
load
"
,
deferred
.
resolve
.
bind
(
deferred
));
return
new
RSVP
.
Promise
(
function
(
resolve
,
reject
,
notify
)
{
fr
.
addEventListener
(
"
error
"
,
deferred
.
reject
.
bind
(
deferred
));
fr
.
addEventListener
(
"
load
"
,
resolve
);
fr
.
addEventListener
(
"
progress
"
,
deferred
.
notify
.
bind
(
deferred
));
fr
.
addEventListener
(
"
error
"
,
reject
);
fr
.
addEventListener
(
"
progress
"
,
notify
);
fr
.
readAsBinaryString
(
blob
);
fr
.
readAsBinaryString
(
blob
);
return
deferred
.
promise
;
},
function
()
{
fr
.
abort
();
});
}
}
exports
.
util
.
readBlobAsBinaryString
=
readBlobAsBinaryString
;
exports
.
util
.
readBlobAsBinaryString
=
readBlobAsBinaryString
;
function
readBlobAsArrayBuffer
(
blob
)
{
function
readBlobAsArrayBuffer
(
blob
)
{
var
deferred
=
new
Deferred
(),
fr
=
new
FileReader
();
var
fr
=
new
FileReader
();
fr
.
addEventListener
(
"
load
"
,
deferred
.
resolve
.
bind
(
deferred
));
return
new
RSVP
.
Promise
(
function
(
resolve
,
reject
,
notify
)
{
fr
.
addEventListener
(
"
error
"
,
deferred
.
reject
.
bind
(
deferred
));
fr
.
addEventListener
(
"
load
"
,
resolve
);
fr
.
addEventListener
(
"
progress
"
,
deferred
.
notify
.
bind
(
deferred
));
fr
.
addEventListener
(
"
error
"
,
reject
);
fr
.
addEventListener
(
"
progress
"
,
notify
);
fr
.
readAsArrayBuffer
(
blob
);
fr
.
readAsArrayBuffer
(
blob
);
return
deferred
.
promise
;
},
function
()
{
fr
.
abort
();
});
}
}
exports
.
util
.
readBlobAsArrayBuffer
=
readBlobAsArrayBuffer
;
exports
.
util
.
readBlobAsArrayBuffer
=
readBlobAsArrayBuffer
;
function
readBlobAsText
(
blob
)
{
function
readBlobAsText
(
blob
)
{
var
deferred
=
new
Deferred
(),
fr
=
new
FileReader
();
var
fr
=
new
FileReader
();
fr
.
addEventListener
(
"
load
"
,
deferred
.
resolve
.
bind
(
deferred
));
return
new
RSVP
.
Promise
(
function
(
resolve
,
reject
,
notify
)
{
fr
.
addEventListener
(
"
error
"
,
deferred
.
reject
.
bind
(
deferred
));
fr
.
addEventListener
(
"
load
"
,
resolve
);
fr
.
addEventListener
(
"
progress
"
,
deferred
.
notify
.
bind
(
deferred
));
fr
.
addEventListener
(
"
error
"
,
reject
);
fr
.
addEventListener
(
"
progress
"
,
notify
);
fr
.
readAsText
(
blob
);
fr
.
readAsText
(
blob
);
return
deferred
.
promise
;
},
function
()
{
fr
.
abort
();
});
}
}
exports
.
util
.
readBlobAsText
=
readBlobAsText
;
exports
.
util
.
readBlobAsText
=
readBlobAsText
;
...
@@ -355,7 +364,9 @@ exports.util.readBlobAsText = readBlobAsText;
...
@@ -355,7 +364,9 @@ exports.util.readBlobAsText = readBlobAsText;
* @return {Promise} The promise
* @return {Promise} The promise
*/
*/
function
ajax
(
param
)
{
function
ajax
(
param
)
{
var
k
,
xhr
=
new
XMLHttpRequest
(),
deferred
=
new
Deferred
();
var
xhr
=
new
XMLHttpRequest
();
return
new
RSVP
.
Promise
(
function
(
resolve
,
reject
,
notify
)
{
var
k
;
xhr
.
open
(
param
.
type
||
"
GET
"
,
param
.
url
,
true
);
xhr
.
open
(
param
.
type
||
"
GET
"
,
param
.
url
,
true
);
xhr
.
responseType
=
param
.
dataType
||
""
;
xhr
.
responseType
=
param
.
dataType
||
""
;
if
(
typeof
param
.
headers
===
'
object
'
&&
param
.
headers
!==
null
)
{
if
(
typeof
param
.
headers
===
'
object
'
&&
param
.
headers
!==
null
)
{
...
@@ -367,17 +378,19 @@ function ajax(param) {
...
@@ -367,17 +378,19 @@ function ajax(param) {
}
}
xhr
.
addEventListener
(
"
load
"
,
function
(
e
)
{
xhr
.
addEventListener
(
"
load
"
,
function
(
e
)
{
if
(
e
.
target
.
status
>=
400
)
{
if
(
e
.
target
.
status
>=
400
)
{
return
deferred
.
reject
(
e
);
return
reject
(
e
);
}
}
deferred
.
resolve
(
e
);
resolve
(
e
);
});
});
xhr
.
addEventListener
(
"
error
"
,
deferred
.
reject
.
bind
(
deferred
)
);
xhr
.
addEventListener
(
"
error
"
,
reject
);
xhr
.
addEventListener
(
"
progress
"
,
deferred
.
notify
.
bind
(
deferred
)
);
xhr
.
addEventListener
(
"
progress
"
,
notify
);
if
(
typeof
param
.
beforeSend
===
'
function
'
)
{
if
(
typeof
param
.
beforeSend
===
'
function
'
)
{
param
.
beforeSend
(
xhr
);
param
.
beforeSend
(
xhr
);
}
}
xhr
.
send
(
param
.
data
);
xhr
.
send
(
param
.
data
);
return
deferred
.
promise
;
},
function
()
{
xhr
.
abort
();
});
}
}
exports
.
util
.
ajax
=
ajax
;
exports
.
util
.
ajax
=
ajax
;
...
...
src/jio/features/jobChecker.js
View file @
3e152964
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true, unparam: true */
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true, unparam: true */
/*global arrayInsert, indexOf, deepClone, defaults,
IODeferred
*/
/*global arrayInsert, indexOf, deepClone, defaults,
restCommandRejecter
*/
// creates
// creates
// - some defaults job rule actions
// - some defaults job rule actions
...
@@ -8,11 +8,12 @@ function enableJobChecker(jio, shared, options) {
...
@@ -8,11 +8,12 @@ function enableJobChecker(jio, shared, options) {
// dependencies
// dependencies
// - shared.jobs Object Array
// - shared.jobs Object Array
// - param.promise Object
// creates
// creates
// - shared.job_rules Array
// - shared.job_rules Array
// uses 'job' event
s
// uses 'job' event
var
i
;
var
i
;
...
@@ -20,24 +21,25 @@ function enableJobChecker(jio, shared, options) {
...
@@ -20,24 +21,25 @@ function enableJobChecker(jio, shared, options) {
shared
.
job_rule_actions
=
{
shared
.
job_rule_actions
=
{
wait
:
function
(
original_job
,
new_job
)
{
wait
:
function
(
original_job
,
new_job
)
{
original_job
.
deferred
.
promise
.
always
(
function
()
{
original_job
.
promise
.
always
(
function
()
{
shared
.
emit
(
'
job
'
,
new_job
);
shared
.
emit
(
'
job
'
,
new_job
);
});
});
new_job
.
state
=
'
waiting
'
;
new_job
.
state
=
'
waiting
'
;
new_job
.
modified
=
new
Date
();
new_job
.
modified
=
new
Date
();
},
},
update
:
function
(
original_job
,
new_job
)
{
update
:
function
(
original_job
,
new_job
)
{
if
(
!
new_job
.
deferred
)
{
if
(
!
new_job
.
solver
)
{
// promise associated to the job
// promise associated to the job
new_job
.
state
=
'
done
'
;
new_job
.
state
=
'
done
'
;
shared
.
emit
(
'
jobDone
'
,
new_job
);
shared
.
emit
(
'
jobDone
'
,
new_job
);
}
else
{
}
else
{
if
(
!
original_job
.
deferred
)
{
if
(
!
original_job
.
solver
)
{
original_job
.
deferred
=
new_job
.
deferred
;
original_job
.
solver
=
new_job
.
solver
;
}
else
{
}
else
{
original_job
.
deferred
.
promise
.
original_job
.
promise
.
then
(
done
(
new_job
.
command
.
resolve
).
new_job
.
command
.
resolve
,
fail
(
new_job
.
command
.
reject
);
new_job
.
command
.
reject
);
}
}
}
}
new_job
.
state
=
'
running
'
;
new_job
.
state
=
'
running
'
;
...
@@ -46,11 +48,11 @@ function enableJobChecker(jio, shared, options) {
...
@@ -46,11 +48,11 @@ function enableJobChecker(jio, shared, options) {
deny
:
function
(
original_job
,
new_job
)
{
deny
:
function
(
original_job
,
new_job
)
{
new_job
.
state
=
'
fail
'
;
new_job
.
state
=
'
fail
'
;
new_job
.
modified
=
new
Date
();
new_job
.
modified
=
new
Date
();
IODeferred
.
createFromParam
(
new_job
).
reject
(
restCommandRejecter
(
new_job
,
[
'
precondition_failed
'
,
'
precondition_failed
'
,
'
command denied
'
,
'
command denied
'
,
'
Command rejected by the job checker.
'
'
Command rejected by the job checker.
'
);
]
);
}
}
};
};
...
...
src/jio/features/jobExecuter.js
View file @
3e152964
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true, unparam: true */
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true, unparam: true */
/*global setTimeout, Job, createStorage, deepClone, IODeferred, min */
/*global setTimeout, Job, createStorage, deepClone, min, restCommandResolver,
restCommandRejecter */
function
enableJobExecuter
(
jio
,
shared
)
{
// , options) {
function
enableJobExecuter
(
jio
,
shared
)
{
// , options) {
...
@@ -46,44 +47,30 @@ function enableJobExecuter(jio, shared) { // , options) {
...
@@ -46,44 +47,30 @@ function enableJobExecuter(jio, shared) { // , options) {
});
});
shared
.
on
(
'
jobDone
'
,
function
(
param
,
args
)
{
shared
.
on
(
'
jobDone
'
,
function
(
param
,
args
)
{
var
d
;
if
(
param
.
state
===
'
running
'
)
{
if
(
param
.
state
===
'
running
'
)
{
param
.
state
=
'
done
'
;
param
.
state
=
'
done
'
;
param
.
modified
=
new
Date
();
param
.
modified
=
new
Date
();
shared
.
emit
(
'
jobEnd
'
,
param
);
shared
.
emit
(
'
jobEnd
'
,
param
);
if
(
param
.
deferred
)
{
if
(
param
.
solver
)
{
d
=
IODeferred
.
createFromDeferred
(
restCommandResolver
(
param
,
args
);
param
.
method
,
param
.
kwargs
,
param
.
options
,
param
.
deferred
);
d
.
resolve
.
apply
(
d
,
args
);
}
}
}
}
});
});
shared
.
on
(
'
jobFail
'
,
function
(
param
,
args
)
{
shared
.
on
(
'
jobFail
'
,
function
(
param
,
args
)
{
var
d
;
if
(
param
.
state
===
'
running
'
)
{
if
(
param
.
state
===
'
running
'
)
{
param
.
state
=
'
fail
'
;
param
.
state
=
'
fail
'
;
param
.
modified
=
new
Date
();
param
.
modified
=
new
Date
();
shared
.
emit
(
'
jobEnd
'
,
param
);
shared
.
emit
(
'
jobEnd
'
,
param
);
if
(
param
.
deferred
)
{
if
(
param
.
solver
)
{
d
=
IODeferred
.
createFromDeferred
(
restCommandRejecter
(
param
,
args
);
param
.
method
,
param
.
kwargs
,
param
.
options
,
param
.
deferred
);
d
.
reject
.
apply
(
d
,
args
);
}
}
}
}
});
});
shared
.
on
(
'
jobNotify
'
,
function
(
param
,
args
)
{
shared
.
on
(
'
jobNotify
'
,
function
(
param
,
args
)
{
if
(
param
.
state
===
'
running
'
&&
param
.
deferred
)
{
if
(
param
.
state
===
'
running
'
&&
param
.
solver
)
{
param
.
deferred
.
notify
.
apply
(
param
.
deferred
,
args
);
param
.
solver
.
notify
(
args
[
0
]
);
}
}
});
});
}
}
src/jio/features/jobMaker.js
View file @
3e152964
...
@@ -58,7 +58,7 @@ function enableJobMaker(jio, shared, options) {
...
@@ -58,7 +58,7 @@ function enableJobMaker(jio, shared, options) {
shared
.
rest_method_names
.
forEach
(
function
(
method
)
{
shared
.
rest_method_names
.
forEach
(
function
(
method
)
{
shared
.
on
(
method
,
function
(
param
)
{
shared
.
on
(
method
,
function
(
param
)
{
if
(
param
.
deferred
)
{
if
(
param
.
solver
)
{
// params are good
// params are good
shared
.
emit
(
'
job
'
,
param
);
shared
.
emit
(
'
job
'
,
param
);
}
}
...
...
src/jio/features/restApi.js
View file @
3e152964
/*jslint indent: 2, maxlen: 80, sloppy: true */
/*jslint indent: 2, maxlen: 80, sloppy: true */
/*global arrayValuesToTypeDict, dictClear,
Deferred
, deepClone */
/*global arrayValuesToTypeDict, dictClear,
RSVP
, deepClone */
// adds methods to JIO
// adds methods to JIO
// - post
// - post
...
@@ -18,7 +18,12 @@
...
@@ -18,7 +18,12 @@
// - method string
// - method string
// - kwargs object
// - kwargs object
// - options object
// - options object
// - command object
// - solver object
// - solver.resolve function
// - solver.reject function
// - solver.notify function
// - cancellers object
// - promise object
function
enableRestAPI
(
jio
,
shared
)
{
// (jio, shared, options)
function
enableRestAPI
(
jio
,
shared
)
{
// (jio, shared, options)
...
@@ -36,7 +41,7 @@ function enableRestAPI(jio, shared) { // (jio, shared, options)
...
@@ -36,7 +41,7 @@ function enableRestAPI(jio, shared) { // (jio, shared, options)
];
];
function
prepareParamAndEmit
(
method
,
storage_spec
,
args
)
{
function
prepareParamAndEmit
(
method
,
storage_spec
,
args
)
{
var
promise
,
callback
,
type_dict
,
param
=
{};
var
callback
,
type_dict
,
param
=
{};
type_dict
=
arrayValuesToTypeDict
(
Array
.
prototype
.
slice
.
call
(
args
));
type_dict
=
arrayValuesToTypeDict
(
Array
.
prototype
.
slice
.
call
(
args
));
type_dict
.
object
=
type_dict
.
object
||
[];
type_dict
.
object
=
type_dict
.
object
||
[];
if
(
method
!==
'
allDocs
'
)
{
if
(
method
!==
'
allDocs
'
)
{
...
@@ -49,31 +54,38 @@ function enableRestAPI(jio, shared) { // (jio, shared, options)
...
@@ -49,31 +54,38 @@ function enableRestAPI(jio, shared) { // (jio, shared, options)
}
else
{
}
else
{
param
.
kwargs
=
{};
param
.
kwargs
=
{};
}
}
param
.
solver
=
{};
param
.
options
=
deepClone
(
type_dict
.
object
.
shift
())
||
{};
param
.
options
=
deepClone
(
type_dict
.
object
.
shift
())
||
{};
//param.deferred = new IODeferred(method, param.kwargs, param.options);
param
.
promise
=
new
RSVP
.
Promise
(
function
(
resolve
,
reject
,
notify
)
{
param
.
deferred
=
new
Deferred
();
param
.
solver
.
resolve
=
resolve
;
promise
=
param
.
deferred
.
promise
;
param
.
solver
.
reject
=
reject
;
param
.
solver
.
notify
=
notify
;
},
function
()
{
var
k
;
for
(
k
in
param
.
cancellers
)
{
if
(
param
.
cancellers
.
hasOwnProperty
(
k
))
{
param
.
cancellers
[
k
]();
}
}
});
type_dict
[
'
function
'
]
=
type_dict
[
'
function
'
]
||
[];
type_dict
[
'
function
'
]
=
type_dict
[
'
function
'
]
||
[];
if
(
type_dict
[
'
function
'
].
length
===
1
)
{
if
(
type_dict
[
'
function
'
].
length
===
1
)
{
callback
=
type_dict
[
'
function
'
]
.
shift
()
;
callback
=
type_dict
[
'
function
'
]
[
0
]
;
p
romise
.
done
(
function
(
answer
)
{
p
aram
.
promise
.
then
(
function
(
answer
)
{
callback
(
undefined
,
answer
);
callback
(
undefined
,
answer
);
});
},
function
(
answer
)
{
promise
.
fail
(
function
(
answer
)
{
callback
(
answer
,
undefined
);
callback
(
answer
,
undefined
);
});
});
}
else
if
(
type_dict
[
'
function
'
].
length
>
1
)
{
}
else
if
(
type_dict
[
'
function
'
].
length
>
1
)
{
promise
.
done
(
type_dict
[
'
function
'
].
shift
());
param
.
promise
.
then
(
type_dict
[
'
function
'
][
0
],
promise
.
fail
(
type_dict
[
'
function
'
].
shift
());
type_dict
[
'
function
'
][
1
],
if
(
type_dict
[
'
function
'
].
length
===
1
)
{
type_dict
[
'
function
'
][
2
]);
promise
.
always
(
type_dict
[
'
function
'
].
shift
());
}
}
}
type_dict
=
dictClear
(
type_dict
);
type_dict
=
dictClear
(
type_dict
);
param
.
storage_spec
=
storage_spec
;
param
.
storage_spec
=
storage_spec
;
param
.
method
=
method
;
param
.
method
=
method
;
shared
.
emit
(
method
,
param
);
shared
.
emit
(
method
,
param
);
return
promise
;
return
p
aram
.
p
romise
;
}
}
shared
.
createRestApi
=
function
(
storage_spec
,
that
)
{
shared
.
createRestApi
=
function
(
storage_spec
,
that
)
{
...
...
src/jio/features/restParamChecker.js
View file @
3e152964
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true, unparam: true */
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true, unparam: true */
/*global Blob,
IODeferred
, Metadata */
/*global Blob,
restCommandRejecter
, Metadata */
function
enableRestParamChecker
(
jio
,
shared
)
{
function
enableRestParamChecker
(
jio
,
shared
)
{
// dependencies
// dependencies
// - param.
deferred
// - param.
solver
// - param.kwargs
// - param.kwargs
// checks the kwargs and convert value if necessary
// checks the kwargs and convert value if necessary
...
@@ -17,12 +17,12 @@ function enableRestParamChecker(jio, shared) {
...
@@ -17,12 +17,12 @@ function enableRestParamChecker(jio, shared) {
function
checkId
(
param
)
{
function
checkId
(
param
)
{
if
(
typeof
param
.
kwargs
.
_id
!==
'
string
'
||
param
.
kwargs
.
_id
===
''
)
{
if
(
typeof
param
.
kwargs
.
_id
!==
'
string
'
||
param
.
kwargs
.
_id
===
''
)
{
IODeferred
.
createFromParam
(
param
).
reject
(
restCommandRejecter
(
param
,
[
'
bad_request
'
,
'
bad_request
'
,
'
wrong document id
'
,
'
wrong document id
'
,
'
Document id must be a non empty string.
'
'
Document id must be a non empty string.
'
);
]
);
delete
param
.
deferred
;
delete
param
.
solver
;
return
false
;
return
false
;
}
}
return
true
;
return
true
;
...
@@ -31,12 +31,12 @@ function enableRestParamChecker(jio, shared) {
...
@@ -31,12 +31,12 @@ function enableRestParamChecker(jio, shared) {
function
checkAttachmentId
(
param
)
{
function
checkAttachmentId
(
param
)
{
if
(
typeof
param
.
kwargs
.
_attachment
!==
'
string
'
||
if
(
typeof
param
.
kwargs
.
_attachment
!==
'
string
'
||
param
.
kwargs
.
_attachment
===
''
)
{
param
.
kwargs
.
_attachment
===
''
)
{
IODeferred
.
createFromParam
(
param
).
reject
(
restCommandRejecter
(
param
,
[
'
bad_request
'
,
'
bad_request
'
,
'
wrong attachment id
'
,
'
wrong attachment id
'
,
'
Attachment id must be a non empty string.
'
'
Attachment id must be a non empty string.
'
);
]
);
delete
param
.
deferred
;
delete
param
.
solver
;
return
false
;
return
false
;
}
}
return
true
;
return
true
;
...
@@ -84,15 +84,15 @@ function enableRestParamChecker(jio, shared) {
...
@@ -84,15 +84,15 @@ function enableRestParamChecker(jio, shared) {
delete
param
.
kwargs
.
_mimetype
;
delete
param
.
kwargs
.
_mimetype
;
delete
param
.
kwargs
.
_content_type
;
delete
param
.
kwargs
.
_content_type
;
}
else
{
}
else
{
IODeferred
.
createFromParam
(
param
).
reject
(
restCommandRejecter
(
param
,
[
'
bad_request
'
,
'
bad_request
'
,
'
wrong attachment
'
,
'
wrong attachment
'
,
'
Attachment information must be like {"_id": document id,
'
+
'
Attachment information must be like {"_id": document id,
'
+
'
"_attachment": attachment name, "_data": string, ["_mimetype":
'
+
'
"_attachment": attachment name, "_data": string, ["_mimetype":
'
+
'
content type]} or {"_id": document id, "_attachment":
'
+
'
content type]} or {"_id": document id, "_attachment":
'
+
'
attachment name, "_blob": Blob}
'
'
attachment name, "_blob": Blob}
'
);
]
);
delete
param
.
deferred
;
delete
param
.
solver
;
}
}
});
});
...
...
src/jio/intro.js
View file @
3e152964
...
@@ -4,11 +4,11 @@
...
@@ -4,11 +4,11 @@
return
define
(
dependencies
,
module
);
return
define
(
dependencies
,
module
);
}
}
if
(
typeof
exports
===
'
object
'
)
{
if
(
typeof
exports
===
'
object
'
)
{
return
module
(
exports
,
require
(
'
promy
'
),
require
(
'
sha256
'
));
return
module
(
exports
,
require
(
'
rsvp
'
),
require
(
'
sha256
'
));
}
}
window
.
jIO
=
{};
window
.
jIO
=
{};
module
(
window
.
jIO
,
promy
,
{
hex_sha256
:
hex_sha256
});
module
(
window
.
jIO
,
RSVP
,
{
hex_sha256
:
hex_sha256
});
}([
'
exports
'
,
'
promy
'
,
'
sha256
'
],
function
(
exports
,
promy
,
sha256
)
{
}([
'
exports
'
,
'
rsvp
'
,
'
sha256
'
],
function
(
exports
,
RSVP
,
sha256
)
{
"
use strict
"
;
"
use strict
"
;
var
hex_sha256
=
sha256
.
hex_sha256
,
Deferred
=
promy
.
Deferred
;
var
hex_sha256
=
sha256
.
hex_sha256
;
src/promy/promy.js
deleted
100644 → 0
View file @
78fe0cd7
This diff is collapsed.
Click to expand it.
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