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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Aurel
jio
Commits
114045eb
Commit
114045eb
authored
Mar 20, 2017
by
Aurel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
split jio code & remove clearroad parts
parent
384d5dea
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
536 additions
and
884 deletions
+536
-884
Gruntfile.js
Gruntfile.js
+1
-1
nodejs/lib/clearroad/clearroad.js
nodejs/lib/clearroad/clearroad.js
+0
-739
nodejs/lib/clearroad/package.json
nodejs/lib/clearroad/package.json
+0
-19
nodejs/package.json
nodejs/package.json
+0
-45
nodejs/server.js
nodejs/server.js
+0
-69
src/jio-nodejs.js
src/jio-nodejs.js
+532
-0
src/jio.js
src/jio.js
+3
-11
No files found.
Gruntfile.js
View file @
114045eb
...
...
@@ -198,7 +198,7 @@ module.exports = function (grunt) {
'
src/jio.date/*.js
'
,
'
src/jio.js
'
,
'
src/jio
-nodejs
.js
'
,
'
src/jio.storage/replicatestorage.js
'
,
'
src/jio.storage/uuidstorage.js
'
,
...
...
nodejs/lib/clearroad/clearroad.js
deleted
100644 → 0
View file @
384d5dea
function
ClearRoadAccountRegistration
(
login
,
password
)
{
if
(
!
(
this
instanceof
ClearRoadAccountRegistration
))
{
return
new
ClearRoadAccountRegistration
();
}
var
DATABASE
=
"
cr-account-registration
"
;
this
.
jio
=
jIO
.
createJIO
({
type
:
"
replicate
"
,
parallel_operation_amount
:
100
,
use_remote_post
:
false
,
conflict_handling
:
1
,
check_local_modification
:
false
,
check_local_creation
:
true
,
check_local_deletion
:
false
,
check_remote_modification
:
false
,
check_remote_creation
:
false
,
check_remote_deletion
:
false
,
local_sub_storage
:
{
type
:
"
mapping
"
,
id
:
[
"
equalSubProperty
"
,
"
reference
"
],
sub_storage
:
{
type
:
"
query
"
,
sub_storage
:
{
type
:
"
uuid
"
,
sub_storage
:
{
type
:
"
memory
"
,
database
:
DATABASE
}
}
}
},
remote_sub_storage
:
{
type
:
"
mapping
"
,
id
:
[
"
equalSubProperty
"
,
"
reference
"
],
property
:
{
"
portal_type
"
:
[
"
equalValue
"
,
"
Road Account Message
"
],
"
parent_relative_url
"
:
[
"
equalValue
"
,
"
road_account_message_module
"
]},
sub_storage
:
{
type
:
"
erp5
"
,
url
:
"
https://softinst69465.host.vifib.net/erp5/web_site_module/hateoas
"
,
default_view_reference
:
"
jio_view
"
,
login
:
login
,
password
:
password
}
}
});
}
ClearRoadAccountRegistration
.
prototype
=
new
ClearRoadAccountRegistration
();
ClearRoadAccountRegistration
.
prototype
.
constructor
=
ClearRoadAccountRegistration
;
ClearRoadAccountRegistration
.
prototype
.
post
=
function
(){
return
this
.
jio
.
post
.
apply
(
this
.
jio
,
arguments
);
};
ClearRoadAccountRegistration
.
prototype
.
sync
=
function
(){
return
this
.
jio
.
repair
.
apply
(
this
.
jio
,
arguments
);
};
function
ClearRoadAccountRegistrationReport
(
login
,
password
,
day_range
)
{
if
(
!
(
this
instanceof
ClearRoadAccountRegistrationReport
))
{
return
new
ClearRoadAccountRegistrationReport
();
}
var
DATABASE
=
"
cr-account-registration-report
"
;
var
query
=
'
portal_type:"Road Account Message"
'
;
if
(
day_range
!==
undefined
){
var
from_date
=
new
Date
();
from_date
.
setDate
(
from_date
.
getDate
()
-
day_range
);
query
+=
'
AND modification_date: >="
'
+
from_date
.
toJSON
()
+
'
"
'
;
}
this
.
jio
=
jIO
.
createJIO
({
type
:
"
replicate
"
,
parallel_operation_amount
:
100
,
use_remote_post
:
true
,
conflict_handling
:
1
,
query
:
{
query
:
query
,
sort_on
:
[[
'
modification_date
'
,
'
descending
'
]],
limit
:
[
0
,
1234567890
]
},
check_local_modification
:
false
,
check_local_creation
:
false
,
check_local_deletion
:
false
,
check_remote_modification
:
false
,
check_remote_creation
:
true
,
check_remote_deletion
:
false
,
local_sub_storage
:
{
type
:
"
query
"
,
sub_storage
:
{
type
:
"
uuid
"
,
sub_storage
:
{
type
:
"
memory
"
,
database
:
DATABASE
}
}
},
remote_sub_storage
:
{
type
:
"
erp5
"
,
url
:
"
https://softinst69465.host.vifib.net/erp5/web_site_module/hateoas
"
,
default_view_reference
:
"
jio_ingestion_report_view
"
,
login
:
login
,
password
:
password
}
});
}
ClearRoadAccountRegistrationReport
.
prototype
=
new
ClearRoadAccountRegistrationReport
();
ClearRoadAccountRegistrationReport
.
prototype
.
constructor
=
ClearRoadAccountRegistrationReport
;
ClearRoadAccountRegistrationReport
.
prototype
.
sync
=
function
(){
return
this
.
jio
.
repair
.
apply
(
this
.
jio
,
arguments
);
};
ClearRoadAccountRegistrationReport
.
prototype
.
allDocs
=
function
(){
return
this
.
jio
.
allDocs
.
apply
(
this
.
jio
,
[{
select_list
:
[
'
reference
'
,
'
comment
'
,
'
state
'
],
query
:
'
portal_type:"Road Account Message"
'
}]);
};
function
ClearRoadUsageData
(
login
,
password
)
{
if
(
!
(
this
instanceof
ClearRoadUsageData
))
{
return
new
ClearRoadUsageData
();
}
var
DATABASE
=
"
cr-road-usage-data
"
;
this
.
jio
=
jIO
.
createJIO
({
type
:
"
replicate
"
,
parallel_operation_amount
:
100
,
use_remote_post
:
false
,
conflict_handling
:
1
,
check_local_modification
:
false
,
check_local_creation
:
true
,
check_local_deletion
:
false
,
check_remote_modification
:
false
,
check_remote_creation
:
false
,
check_remote_deletion
:
false
,
local_sub_storage
:
{
type
:
"
mapping
"
,
id
:
[
"
equalSubProperty
"
,
"
reference
"
],
sub_storage
:
{
type
:
"
query
"
,
sub_storage
:
{
type
:
"
uuid
"
,
sub_storage
:
{
type
:
"
memory
"
,
database
:
DATABASE
}
}
}
},
remote_sub_storage
:
{
type
:
"
mapping
"
,
id
:
[
"
equalSubProperty
"
,
"
reference
"
],
property
:
{
"
portal_type
"
:
[
"
equalValue
"
,
"
Road Message
"
],
"
parent_relative_url
"
:
[
"
equalValue
"
,
"
road_message_module
"
]},
sub_storage
:
{
type
:
"
erp5
"
,
url
:
"
https://softinst69465.host.vifib.net/erp5/web_site_module/hateoas
"
,
default_view_reference
:
"
jio_view
"
,
login
:
login
,
password
:
password
}
}
});
}
ClearRoadUsageData
.
prototype
=
new
ClearRoadUsageData
();
ClearRoadUsageData
.
prototype
.
constructor
=
ClearRoadUsageData
;
ClearRoadUsageData
.
prototype
.
post
=
function
(){
return
this
.
jio
.
post
.
apply
(
this
.
jio
,
arguments
);
};
ClearRoadUsageData
.
prototype
.
sync
=
function
(){
return
this
.
jio
.
repair
.
apply
(
this
.
jio
,
arguments
);
};
function
ClearRoadUsageDataReport
(
login
,
password
,
day_range
)
{
if
(
!
(
this
instanceof
ClearRoadUsageDataReport
))
{
return
new
ClearRoadUsageDataReport
();
}
var
DATABASE
=
"
cr-road-usage-data-report
"
;
var
query
=
'
portal_type:"Road Message"
'
;
if
(
day_range
!==
undefined
){
var
from_date
=
new
Date
();
from_date
.
setDate
(
from_date
.
getDate
()
-
day_range
);
query
+=
'
AND modification_date: >="
'
+
from_date
.
toJSON
()
+
'
"
'
;
}
this
.
jio
=
jIO
.
createJIO
({
type
:
"
replicate
"
,
parallel_operation_amount
:
100
,
use_remote_post
:
true
,
conflict_handling
:
1
,
query
:
{
query
:
query
,
sort_on
:
[[
'
modification_date
'
,
'
descending
'
]],
limit
:
[
0
,
1234567890
]
},
check_local_modification
:
false
,
check_local_creation
:
false
,
check_local_deletion
:
false
,
check_remote_modification
:
false
,
check_remote_creation
:
true
,
check_remote_deletion
:
false
,
local_sub_storage
:
{
type
:
"
query
"
,
sub_storage
:
{
type
:
"
uuid
"
,
sub_storage
:
{
type
:
"
memory
"
,
database
:
DATABASE
}
}
},
remote_sub_storage
:
{
type
:
"
erp5
"
,
url
:
"
https://softinst69465.host.vifib.net/erp5/web_site_module/hateoas
"
,
default_view_reference
:
"
jio_ingestion_report_view
"
,
login
:
login
,
password
:
password
}
});
}
ClearRoadUsageDataReport
.
prototype
=
new
ClearRoadUsageDataReport
();
ClearRoadUsageDataReport
.
prototype
.
constructor
=
ClearRoadUsageDataReport
;
ClearRoadUsageDataReport
.
prototype
.
sync
=
function
(){
return
this
.
jio
.
repair
.
apply
(
this
.
jio
,
arguments
);
};
ClearRoadUsageDataReport
.
prototype
.
allDocs
=
function
(){
return
this
.
jio
.
allDocs
.
apply
(
this
.
jio
,
[{
select_list
:
[
'
reference
'
,
'
comment
'
,
'
state
'
],
query
:
'
portal_type:"Road Message"
'
}]);
};
function
ClearRoadAccountDirectory
(
login
,
password
)
{
if
(
!
(
this
instanceof
ClearRoadAccountDirectory
))
{
return
new
ClearRoadAccountDirectory
();
}
var
DATABASE
=
"
cr-account-directory
"
;
this
.
jio
=
jIO
.
createJIO
({
type
:
"
replicate
"
,
parallel_operation_amount
:
100
,
use_remote_post
:
true
,
conflict_handling
:
1
,
query
:
{
query
:
'
portal_type:"Road Account"
'
,
sort_on
:
[[
'
modification_date
'
,
'
descending
'
]],
limit
:
[
0
,
1234567890
]
},
check_local_modification
:
false
,
check_local_creation
:
false
,
check_local_deletion
:
false
,
check_remote_modification
:
false
,
check_remote_creation
:
true
,
check_remote_deletion
:
false
,
local_sub_storage
:
{
type
:
"
query
"
,
sub_storage
:
{
type
:
"
uuid
"
,
sub_storage
:
{
type
:
"
memory
"
,
database
:
DATABASE
}
}
},
remote_sub_storage
:
{
type
:
"
erp5
"
,
url
:
"
https://softinst69465.host.vifib.net/erp5/web_site_module/hateoas
"
,
default_view_reference
:
"
jio_directory_view
"
,
login
:
login
,
password
:
password
}
});
}
ClearRoadAccountDirectory
.
prototype
=
new
ClearRoadAccountDirectory
();
ClearRoadAccountDirectory
.
prototype
.
constructor
=
ClearRoadAccountDirectory
;
ClearRoadAccountDirectory
.
prototype
.
sync
=
function
(){
return
this
.
jio
.
repair
.
apply
(
this
.
jio
,
arguments
);
};
ClearRoadAccountDirectory
.
prototype
.
allDocs
=
function
(){
return
this
.
jio
.
allDocs
.
apply
(
this
.
jio
,
[{
select_list
:
[
'
reference
'
,
'
registrations
'
],
query
:
'
portal_type:"Road Account"
'
}]);
};
function
ClearRoadAccountBalance
(
login
,
password
,
reference
)
{
if
(
!
(
this
instanceof
ClearRoadAccountBalance
))
{
return
new
ClearRoadAccountBalance
();
}
var
DATABASE
=
"
cr-account-balance
"
;
if
(
reference
===
undefined
){
return
;
}
this
.
jio
=
jIO
.
createJIO
({
type
:
"
replicate
"
,
parallel_operation_amount
:
100
,
use_remote_post
:
true
,
conflict_handling
:
1
,
query
:
{
query
:
'
portal_type:"Billing Period" AND reference: ="
'
+
reference
+
'
"
'
},
check_local_modification
:
false
,
check_local_creation
:
false
,
check_local_deletion
:
false
,
check_remote_modification
:
false
,
check_remote_creation
:
true
,
check_remote_deletion
:
false
,
local_sub_storage
:
{
type
:
"
query
"
,
sub_storage
:
{
type
:
"
uuid
"
,
sub_storage
:
{
type
:
"
memory
"
,
database
:
DATABASE
}
}
},
remote_sub_storage
:
{
type
:
"
erp5
"
,
url
:
"
https://softinst69465.host.vifib.net/erp5/web_site_module/hateoas
"
,
default_view_reference
:
"
jio_balance_view
"
,
login
:
login
,
password
:
password
}
});
}
ClearRoadAccountBalance
.
prototype
=
new
ClearRoadAccountBalance
();
ClearRoadAccountBalance
.
prototype
.
constructor
=
ClearRoadAccountBalance
;
ClearRoadAccountBalance
.
prototype
.
sync
=
function
(){
return
this
.
jio
.
repair
.
apply
(
this
.
jio
,
arguments
);
};
ClearRoadAccountBalance
.
prototype
.
allDocs
=
function
(){
return
this
.
jio
.
allDocs
.
apply
(
this
.
jio
,
[{
select_list
:
[
'
reference
'
,
'
start_date
'
,
'
stop_date
'
,
'
balance
'
],
query
:
'
portal_type:"Billing Period"
'
}]);
};
function
ClearRoadEvent
(
login
,
password
)
{
if
(
!
(
this
instanceof
ClearRoadEvent
))
{
return
new
ClearRoadEvent
();
}
var
DATABASE
=
"
cr-event-data
"
;
this
.
jio
=
jIO
.
createJIO
({
type
:
"
replicate
"
,
parallel_operation_amount
:
100
,
use_remote_post
:
false
,
conflict_handling
:
1
,
check_local_modification
:
false
,
check_local_creation
:
true
,
check_local_deletion
:
false
,
check_remote_modification
:
false
,
check_remote_creation
:
false
,
check_remote_deletion
:
false
,
local_sub_storage
:
{
type
:
"
mapping
"
,
id
:
[
"
equalSubProperty
"
,
"
reference
"
],
sub_storage
:
{
type
:
"
query
"
,
sub_storage
:
{
type
:
"
uuid
"
,
sub_storage
:
{
type
:
"
memory
"
,
database
:
DATABASE
}
}
}
},
remote_sub_storage
:
{
type
:
"
mapping
"
,
id
:
[
"
equalSubProperty
"
,
"
reference
"
],
property
:
{
"
portal_type
"
:
[
"
equalValue
"
,
"
Road Event Message
"
],
"
parent_relative_url
"
:
[
"
equalValue
"
,
"
road_event_message_module
"
]},
sub_storage
:
{
type
:
"
erp5
"
,
url
:
"
https://softinst69465.host.vifib.net/erp5/web_site_module/hateoas
"
,
default_view_reference
:
"
jio_view
"
,
login
:
login
,
password
:
password
}
}
});
}
ClearRoadEvent
.
prototype
=
new
ClearRoadEvent
();
ClearRoadEvent
.
prototype
.
constructor
=
ClearRoadEvent
;
ClearRoadEvent
.
prototype
.
post
=
function
(){
return
this
.
jio
.
post
.
apply
(
this
.
jio
,
arguments
);
};
ClearRoadEvent
.
prototype
.
sync
=
function
(){
return
this
.
jio
.
repair
.
apply
(
this
.
jio
,
arguments
);
};
function
ClearRoadEventReport
(
login
,
password
,
day_range
)
{
if
(
!
(
this
instanceof
ClearRoadEventReport
))
{
return
new
ClearRoadEventReport
();
}
var
DATABASE
=
"
cr-event-report
"
;
var
query
=
'
portal_type:"Road Event Message"
'
;
if
(
day_range
!==
undefined
){
var
from_date
=
new
Date
();
from_date
.
setDate
(
from_date
.
getDate
()
-
day_range
);
query
+=
'
AND modification_date: >="
'
+
from_date
.
toJSON
()
+
'
"
'
;
}
this
.
jio
=
jIO
.
createJIO
({
type
:
"
replicate
"
,
parallel_operation_amount
:
100
,
use_remote_post
:
true
,
conflict_handling
:
1
,
query
:
{
query
:
query
,
sort_on
:
[[
'
modification_date
'
,
'
descending
'
]],
limit
:
[
0
,
1234567890
]
},
check_local_modification
:
false
,
check_local_creation
:
false
,
check_local_deletion
:
false
,
check_remote_modification
:
false
,
check_remote_creation
:
true
,
check_remote_deletion
:
false
,
local_sub_storage
:
{
type
:
"
query
"
,
sub_storage
:
{
type
:
"
uuid
"
,
sub_storage
:
{
type
:
"
memory
"
,
database
:
DATABASE
}
}
},
remote_sub_storage
:
{
type
:
"
erp5
"
,
url
:
"
https://softinst69465.host.vifib.net/erp5/web_site_module/hateoas
"
,
default_view_reference
:
"
jio_ingestion_report_view
"
,
login
:
login
,
password
:
password
}
});
}
ClearRoadEventReport
.
prototype
=
new
ClearRoadEventReport
();
ClearRoadEventReport
.
prototype
.
constructor
=
ClearRoadEventReport
;
ClearRoadEventReport
.
prototype
.
sync
=
function
(){
return
this
.
jio
.
repair
.
apply
(
this
.
jio
,
arguments
);
};
ClearRoadEventReport
.
prototype
.
allDocs
=
function
(){
return
this
.
jio
.
allDocs
.
apply
(
this
.
jio
,
[{
select_list
:
[
'
reference
'
,
'
comment
'
,
'
state
'
],
query
:
'
portal_type:"Road Event Message"
'
}]);
};
function
ClearRoadEventDirectory
(
login
,
password
,
day_range
)
{
if
(
!
(
this
instanceof
ClearRoadEventDirectory
))
{
return
new
ClearRoadEventDirectory
();
}
var
DATABASE
=
"
cr-event-directory
"
;
var
query
=
'
portal_type:"Road Event" AND simulation_state: !="rejected"
'
;
if
(
day_range
!==
undefined
){
var
from_date
=
new
Date
();
from_date
.
setDate
(
from_date
.
getDate
()
-
day_range
);
query
+=
'
AND modification_date: >="
'
+
from_date
.
toJSON
()
+
'
"
'
;
}
this
.
jio
=
jIO
.
createJIO
({
type
:
"
replicate
"
,
parallel_operation_amount
:
100
,
use_remote_post
:
true
,
conflict_handling
:
1
,
query
:
{
query
:
query
,
sort_on
:
[[
'
modification_date
'
,
'
descending
'
]],
limit
:
[
0
,
1234567890
]
},
check_local_modification
:
false
,
check_local_creation
:
false
,
check_local_deletion
:
false
,
check_remote_modification
:
false
,
check_remote_creation
:
true
,
check_remote_deletion
:
false
,
local_sub_storage
:
{
type
:
"
query
"
,
sub_storage
:
{
type
:
"
uuid
"
,
sub_storage
:
{
type
:
"
memory
"
,
database
:
DATABASE
}
}
},
remote_sub_storage
:
{
type
:
"
erp5
"
,
url
:
"
https://softinst69465.host.vifib.net/erp5/web_site_module/hateoas
"
,
default_view_reference
:
"
jio_view
"
,
login
:
login
,
password
:
password
}
});
}
ClearRoadEventDirectory
.
prototype
=
new
ClearRoadEventDirectory
();
ClearRoadEventDirectory
.
prototype
.
constructor
=
ClearRoadEventDirectory
;
ClearRoadEventDirectory
.
prototype
.
sync
=
function
(){
return
this
.
jio
.
repair
.
apply
(
this
.
jio
,
arguments
);
};
ClearRoadEventDirectory
.
prototype
.
allDocs
=
function
(){
return
this
.
jio
.
allDocs
.
apply
(
this
.
jio
,
[{
select_list
:
[
'
event_date
'
,
'
report_date
'
,
'
obu_reference
'
,
'
vehicle_reference
'
,
'
type
'
,
'
state
'
],
query
:
'
portal_type:"Road Event"
'
}]);
};
function
ClearRoadBillingPeriodRegistration
(
login
,
password
)
{
if
(
!
(
this
instanceof
ClearRoadBillingPeriodRegistration
))
{
return
new
ClearRoadBillingPeriodRegistration
();
}
var
DATABASE
=
"
cr-billing-period-registration
"
;
this
.
jio
=
jIO
.
createJIO
({
type
:
"
replicate
"
,
parallel_operation_amount
:
100
,
use_remote_post
:
false
,
conflict_handling
:
1
,
check_local_modification
:
false
,
check_local_creation
:
true
,
check_local_deletion
:
false
,
check_remote_modification
:
false
,
check_remote_creation
:
false
,
check_remote_deletion
:
false
,
local_sub_storage
:
{
type
:
"
mapping
"
,
id
:
[
"
equalSubProperty
"
,
"
reference
"
],
sub_storage
:
{
type
:
"
query
"
,
sub_storage
:
{
type
:
"
uuid
"
,
sub_storage
:
{
type
:
"
memory
"
,
database
:
DATABASE
}
}
}
},
remote_sub_storage
:
{
type
:
"
mapping
"
,
id
:
[
"
equalSubProperty
"
,
"
reference
"
],
property
:
{
"
portal_type
"
:
[
"
equalValue
"
,
"
Billing Period Message
"
],
"
parent_relative_url
"
:
[
"
equalValue
"
,
"
billing_period_message_module
"
]},
sub_storage
:
{
type
:
"
erp5
"
,
url
:
"
https://softinst69465.host.vifib.net/erp5/web_site_module/hateoas
"
,
default_view_reference
:
"
jio_view
"
,
login
:
login
,
password
:
password
,
}
}
});
}
ClearRoadBillingPeriodRegistration
.
prototype
=
new
ClearRoadBillingPeriodRegistration
();
ClearRoadBillingPeriodRegistration
.
prototype
.
constructor
=
ClearRoadBillingPeriodRegistration
;
ClearRoadBillingPeriodRegistration
.
prototype
.
post
=
function
(){
return
this
.
jio
.
post
.
apply
(
this
.
jio
,
arguments
);
};
ClearRoadBillingPeriodRegistration
.
prototype
.
sync
=
function
(){
return
this
.
jio
.
repair
.
apply
(
this
.
jio
,
arguments
);
};
function
ClearRoadBillingPeriodRegistrationReport
(
login
,
password
,
day_range
)
{
if
(
!
(
this
instanceof
ClearRoadBillingPeriodRegistrationReport
))
{
return
new
ClearRoadBillingPeriodRegistrationReport
();
}
var
DATABASE
=
"
cr-billing-period-registration-report
"
;
var
query
=
'
portal_type:"Billing Period Message"
'
;
if
(
day_range
!==
undefined
){
var
from_date
=
new
Date
();
from_date
.
setDate
(
from_date
.
getDate
()
-
day_range
);
query
+=
'
AND modification_date: >="
'
+
from_date
.
toJSON
()
+
'
"
'
;
}
this
.
jio
=
jIO
.
createJIO
({
type
:
"
replicate
"
,
parallel_operation_amount
:
100
,
use_remote_post
:
true
,
conflict_handling
:
1
,
query
:
{
query
:
query
,
sort_on
:
[[
'
modification_date
'
,
'
descending
'
]],
limit
:
[
0
,
1234567890
]
},
check_local_modification
:
false
,
check_local_creation
:
false
,
check_local_deletion
:
false
,
check_remote_modification
:
false
,
check_remote_creation
:
true
,
check_remote_deletion
:
false
,
local_sub_storage
:
{
type
:
"
query
"
,
sub_storage
:
{
type
:
"
uuid
"
,
sub_storage
:
{
type
:
"
memory
"
,
database
:
DATABASE
}
}
},
remote_sub_storage
:
{
type
:
"
erp5
"
,
url
:
"
https://softinst69465.host.vifib.net/erp5/web_site_module/hateoas
"
,
default_view_reference
:
"
jio_ingestion_report_view
"
,
login
:
login
,
password
:
password
}
});
}
ClearRoadBillingPeriodRegistrationReport
.
prototype
=
new
ClearRoadBillingPeriodRegistrationReport
();
ClearRoadBillingPeriodRegistrationReport
.
prototype
.
constructor
=
ClearRoadBillingPeriodRegistrationReport
;
ClearRoadBillingPeriodRegistrationReport
.
prototype
.
sync
=
function
(){
return
this
.
jio
.
repair
.
apply
(
this
.
jio
,
arguments
);
};
ClearRoadBillingPeriodRegistrationReport
.
prototype
.
allDocs
=
function
(){
return
this
.
jio
.
allDocs
.
apply
(
this
.
jio
,
[{
select_list
:
[
'
reference
'
,
'
comment
'
,
'
state
'
],
query
:
'
portal_type:"Billing Period Message"
'
}]);
};
function
ClearRoadBillingPeriodDirectory
(
login
,
password
)
{
if
(
!
(
this
instanceof
ClearRoadBillingPeriodDirectory
))
{
return
new
ClearRoadBillingPeriodDirectory
();
}
var
DATABASE
=
"
cr-billing-period-directory
"
;
this
.
jio
=
jIO
.
createJIO
({
type
:
"
replicate
"
,
parallel_operation_amount
:
100
,
use_remote_post
:
true
,
conflict_handling
:
1
,
query
:
{
query
:
'
portal_type:"Billing Period"
'
,
sort_on
:
[[
'
modification_date
'
,
'
descending
'
]],
limit
:
[
0
,
1234567890
]
},
check_local_modification
:
false
,
check_local_creation
:
false
,
check_local_deletion
:
false
,
check_remote_modification
:
false
,
check_remote_creation
:
true
,
check_remote_deletion
:
false
,
local_sub_storage
:
{
type
:
"
query
"
,
sub_storage
:
{
type
:
"
uuid
"
,
sub_storage
:
{
type
:
"
memory
"
,
database
:
DATABASE
}
}
},
remote_sub_storage
:
{
type
:
"
erp5
"
,
url
:
"
https://softinst69465.host.vifib.net/erp5/web_site_module/hateoas
"
,
default_view_reference
:
"
jio_directory_view
"
,
login
:
login
,
password
:
password
}
});
}
ClearRoadBillingPeriodDirectory
.
prototype
=
new
ClearRoadBillingPeriodDirectory
();
ClearRoadBillingPeriodDirectory
.
prototype
.
constructor
=
ClearRoadBillingPeriodDirectory
;
ClearRoadBillingPeriodDirectory
.
prototype
.
sync
=
function
(){
return
this
.
jio
.
repair
.
apply
(
this
.
jio
,
arguments
);
};
ClearRoadBillingPeriodDirectory
.
prototype
.
allDocs
=
function
(){
return
this
.
jio
.
allDocs
.
apply
(
this
.
jio
,
[{
select_list
:
[
'
reference
'
,
'
start_date
'
,
'
stop_date
'
],
query
:
'
portal_type:"Billing Period"
'
}]);
};
function
ClearRoadTransactionDirectory
(
login
,
password
,
account
)
{
if
(
!
(
this
instanceof
ClearRoadTransactionDirectory
))
{
return
new
ClearRoadTransactionDirectory
();
}
var
DATABASE
=
"
cr-transaction-directory
"
;
var
query
=
'
portal_type:"Road Account"
'
;
if
(
account
!==
undefined
){
query
+=
'
AND reference: ="
'
+
account
+
'
"
'
;
}
this
.
jio
=
jIO
.
createJIO
({
type
:
"
replicate
"
,
parallel_operation_amount
:
100
,
use_remote_post
:
true
,
conflict_handling
:
1
,
query
:
{
query
:
query
,
sort_on
:
[[
'
modification_date
'
,
'
descending
'
]],
limit
:
[
0
,
1234567890
]
},
check_local_modification
:
false
,
check_local_creation
:
false
,
check_local_deletion
:
false
,
check_remote_modification
:
false
,
check_remote_creation
:
true
,
check_remote_deletion
:
false
,
local_sub_storage
:
{
type
:
"
query
"
,
sub_storage
:
{
type
:
"
uuid
"
,
sub_storage
:
{
type
:
"
memory
"
,
database
:
DATABASE
}
}
},
remote_sub_storage
:
{
type
:
"
erp5
"
,
url
:
"
https://softinst69465.host.vifib.net/erp5/web_site_module/hateoas
"
,
default_view_reference
:
"
jio_transactions_view
"
,
login
:
login
,
password
:
password
}
});
}
ClearRoadTransactionDirectory
.
prototype
=
new
ClearRoadTransactionDirectory
();
ClearRoadTransactionDirectory
.
prototype
.
constructor
=
ClearRoadTransactionDirectory
;
ClearRoadTransactionDirectory
.
prototype
.
sync
=
function
(){
return
this
.
jio
.
repair
.
apply
(
this
.
jio
,
arguments
);
};
ClearRoadTransactionDirectory
.
prototype
.
allDocs
=
function
(){
return
this
.
jio
.
allDocs
.
apply
(
this
.
jio
,
[{
select_list
:
[
'
reference
'
,
'
transactions
'
],
query
:
'
portal_type:"Road Account"
'
}]);
};
// Exports to node
exports
.
ClearRoadAccountRegistration
=
ClearRoadAccountRegistration
;
exports
.
ClearRoadAccountRegistrationReport
=
ClearRoadAccountRegistrationReport
;
exports
.
ClearRoadUsageData
=
ClearRoadUsageData
;
exports
.
ClearRoadUsageDataReport
=
ClearRoadUsageDataReport
;
exports
.
ClearRoadAccountDirectory
=
ClearRoadAccountDirectory
;
exports
.
ClearRoadAccountBalance
=
ClearRoadAccountBalance
;
exports
.
ClearRoadEvent
=
ClearRoadEvent
;
exports
.
ClearRoadEventReport
=
ClearRoadEventReport
;
exports
.
ClearRoadEventDirectory
=
ClearRoadEventDirectory
;
exports
.
ClearRoadBillingPeriodRegistration
=
ClearRoadBillingPeriodRegistration
;
exports
.
ClearRoadBillingPeriodRegistrationReport
=
ClearRoadBillingPeriodRegistrationReport
;
exports
.
ClearRoadBillingPeriodDirectory
=
ClearRoadBillingPeriodDirectory
;
exports
.
ClearRoadTransactionDirectory
=
ClearRoadTransactionDirectory
;
nodejs/lib/clearroad/package.json
deleted
100644 → 0
View file @
384d5dea
{
"name"
:
"clearroad"
,
"version"
:
"1.0.0"
,
"description"
:
"ClearRoad Lib based on JIO"
,
"main"
:
"clearroad.js"
,
"scripts"
:
{
"test"
:
"echo
\"
Error: no test specified
\"
&& exit 1"
},
"repository"
:
{
"type"
:
"git"
,
"url"
:
"lab.nexedi.com/nexedi/jio"
},
"keywords"
:
[
"clearroad"
,
"jio"
],
"author"
:
"Aurélien Calonne"
,
"license"
:
"ISC"
}
nodejs/package.json
deleted
100644 → 0
View file @
384d5dea
{
"//1"
:
"describes your app and its dependencies"
,
"//2"
:
"https://docs.npmjs.com/files/package.json"
,
"//3"
:
"updating this file will download and update your packages"
,
"name"
:
"clearroad-nodejs"
,
"version"
:
"0.0.1"
,
"description"
:
"ClearRoad API on Node.js"
,
"main"
:
"server.js"
,
"scripts"
:
{
"start"
:
"node server.js"
},
"dependencies"
:
{
"express"
:
"^4.14.1"
,
"stream-buffer"
:
"latest"
,
"xhr2"
:
"latest"
,
"rsvp"
:
"git+https://lab.nexedi.com/nexedi/rsvp.js.git"
,
"uritemplate"
:
"latest"
,
"moment"
:
"file:lib/moment"
,
"navigator"
:
"latest"
,
"rusha"
:
"latest"
,
"form-data"
:
"latest"
,
"atob"
:
"latest"
,
"html5"
:
"file:lib/html5"
,
"node-localstorage"
:
"latest"
,
"btoa"
:
"latest"
,
"xhr2"
:
"latest"
,
"stream-buffers"
:
"latest"
,
"clearroad"
:
"file:lib/clearroad"
,
"jio"
:
"file:lib/jio"
,
"urijs"
:
"latest"
},
"engines"
:
{
"node"
:
"6.9.x"
},
"repository"
:
{
"url"
:
""
},
"license"
:
""
,
"keywords"
:
[
"node"
,
"jio"
,
"clearroad"
]
}
nodejs/server.js
deleted
100644 → 0
View file @
384d5dea
// server.js
// where your node app starts
"
use strict
"
global
.
URI
=
require
(
"
urijs
"
);
global
.
RSVP
=
require
(
'
rsvp
'
);
global
.
UriTemplate
=
require
(
"
uritemplate
"
);
global
.
moment
=
require
(
'
moment
'
);
global
.
navigator
=
require
(
'
navigator
'
);
global
.
Rusha
=
require
(
'
rusha
'
);
global
.
FormData
=
require
(
'
form-data
'
);
global
.
atob
=
require
(
'
atob
'
);
global
.
FileReader
=
require
(
"
html5
"
).
FileReader
;
global
.
Blob
=
require
(
"
html5
"
).
Blob
;
global
.
localStorage
=
require
(
'
node-localstorage
'
);
global
.
btoa
=
require
(
'
btoa
'
);
global
.
XMLHttpRequest
=
require
(
'
xhr2
'
);
global
.
StreamBuffers
=
require
(
'
stream-buffers
'
);
global
.
window
=
global
;
global
.
sessionStorage
=
{};
var
jIO
=
require
(
'
jio
'
);
var
clearroad
=
require
(
"
clearroad
"
);
var
i
=
0
;
var
cr
=
new
clearroad
.
ClearRoadBillingPeriodRegistration
(
"
testam
"
,
"
testam
"
);
console
.
log
(
"
init
"
);
cr
.
post
({
"
reference
"
:
"
Q421
"
,
"
start_date
"
:
"
2017-02-01T00:00:00Z
"
,
"
stop_date
"
:
"
2017-03-01T00:00:00Z
"
}).
push
(
function
(){
console
.
log
(
"
start sync...
"
);
return
cr
.
sync
();
}).
push
(
function
(){
console
.
info
(
"
Sync done
"
);
}).
push
(
function
()
{
cr
=
new
clearroad
.
ClearRoadBillingPeriodRegistrationReport
(
"
testam
"
,
"
testam
"
,
100
);
return
cr
.
sync
();
}).
push
(
function
(){
console
.
log
(
"
sync done && loading result...
"
)
return
cr
.
allDocs
()
}).
push
(
function
(
result
)
{
console
.
log
(
"
browsing results :
"
+
result
.
data
.
total_rows
);
for
(
i
=
0
;
i
<
result
.
data
.
total_rows
;
i
+=
1
)
{
console
.
log
(
"
Ref :
"
+
result
.
data
.
rows
[
i
].
value
.
reference
+
"
, state :
"
+
result
.
data
.
rows
[
i
].
value
.
state
+
"
, comment
"
+
result
.
data
.
rows
[
i
].
value
.
comment
);
}
console
.
log
(
"
Finished
"
);
}).
push
(
undefined
,
function
(
error
)
{
throw
error
;
});
// init project
var
express
=
require
(
'
express
'
);
var
app
=
express
();
// http://expressjs.com/en/starter/basic-routing.html
app
.
get
(
"
/
"
,
function
(
request
,
response
)
{
response
.
sendFile
(
__dirname
+
'
/views/index.html
'
);
});
// listen for requests :)
var
listener
=
app
.
listen
(
3000
,
function
()
{
console
.
log
(
'
Your app is listening on port
'
+
listener
.
address
().
port
);
});
src/jio-nodejs.js
0 → 100644
View file @
114045eb
/*global window, RSVP, Blob, XMLHttpRequest, QueryFactory, Query, atob,
FileReader, ArrayBuffer, Uint8Array, navigator, FormData, StreamBuffers */
(
function
(
window
,
RSVP
,
Blob
,
QueryFactory
,
Query
,
atob
,
FileReader
,
ArrayBuffer
,
Uint8Array
,
navigator
)
{
"
use strict
"
;
if
(
window
.
openDatabase
===
undefined
)
{
window
.
openDatabase
=
function
()
{
throw
new
Error
(
'
WebSQL is not supported by
'
+
navigator
.
userAgent
);
};
}
/* Safari does not define DOMError */
if
(
window
.
DOMError
===
undefined
)
{
window
.
DOMError
=
{};
}
var
util
=
{},
jIO
;
function
jIOError
(
message
,
status_code
)
{
if
((
message
!==
undefined
)
&&
(
typeof
message
!==
"
string
"
))
{
throw
new
TypeError
(
'
You must pass a string.
'
);
}
this
.
message
=
message
||
"
Default Message
"
;
this
.
status_code
=
status_code
||
500
;
}
jIOError
.
prototype
=
new
Error
();
jIOError
.
prototype
.
constructor
=
jIOError
;
util
.
jIOError
=
jIOError
;
/**
* Send request with XHR and return a promise. xhr.onload: The promise is
* resolved when the status code is lower than 400 with the xhr object as
* first parameter. xhr.onerror: reject with xhr object as first
* parameter. xhr.onprogress: notifies the xhr object.
*
* @param {Object} param The parameters
* @param {String} [param.type="GET"] The request method
* @param {String} [param.dataType=""] The data type to retrieve
* @param {String} param.url The url
* @param {Any} [param.data] The data to send
* @param {Function} [param.beforeSend] A function called just before the
* send request. The first parameter of this function is the XHR object.
* @return {Promise} The promise
*/
function
ajax
(
param
)
{
var
xhr
=
new
XMLHttpRequest
();
return
new
RSVP
.
Promise
(
function
(
resolve
,
reject
,
notify
)
{
var
k
,
buffer
=
new
StreamBuffers
.
WritableStreamBuffer
();
xhr
.
open
(
param
.
type
||
"
GET
"
,
param
.
url
,
true
);
xhr
.
responseType
=
param
.
dataType
||
""
;
if
(
typeof
param
.
headers
===
'
object
'
&&
param
.
headers
!==
null
)
{
for
(
k
in
param
.
headers
)
{
if
(
param
.
headers
.
hasOwnProperty
(
k
))
{
xhr
.
setRequestHeader
(
k
,
param
.
headers
[
k
]);
}
}
}
xhr
.
setRequestHeader
(
"
Accept
"
,
"
*/*
"
);
xhr
.
addEventListener
(
"
load
"
,
function
(
e
)
{
if
(
e
.
target
.
status
>=
400
)
{
return
reject
(
e
);
}
resolve
(
e
);
});
xhr
.
addEventListener
(
"
error
"
,
reject
);
xhr
.
addEventListener
(
"
progress
"
,
notify
);
if
(
typeof
param
.
xhrFields
===
'
object
'
&&
param
.
xhrFields
!==
null
)
{
for
(
k
in
param
.
xhrFields
)
{
if
(
param
.
xhrFields
.
hasOwnProperty
(
k
))
{
xhr
[
k
]
=
param
.
xhrFields
[
k
];
}
}
}
if
(
typeof
param
.
beforeSend
===
'
function
'
)
{
param
.
beforeSend
(
xhr
);
}
if
(
param
.
data
instanceof
FormData
)
{
xhr
.
setRequestHeader
(
"
Content-Type
"
,
"
multipart
\
/form-data; boundary=
"
+
param
.
data
.
getBoundary
());
param
.
data
.
pipe
(
buffer
);
xhr
.
send
(
buffer
.
getContents
());
}
else
{
xhr
.
send
(
param
.
data
);
}
},
function
()
{
xhr
.
abort
();
});
}
util
.
ajax
=
ajax
;
function
readBlobAsText
(
blob
,
encoding
)
{
var
fr
=
new
FileReader
();
return
new
RSVP
.
Promise
(
function
(
resolve
,
reject
,
notify
)
{
fr
.
addEventListener
(
"
load
"
,
resolve
);
fr
.
addEventListener
(
"
error
"
,
reject
);
fr
.
addEventListener
(
"
progress
"
,
notify
);
fr
.
readAsText
(
blob
,
encoding
);
},
function
()
{
fr
.
abort
();
});
}
util
.
readBlobAsText
=
readBlobAsText
;
function
readBlobAsArrayBuffer
(
blob
)
{
var
fr
=
new
FileReader
();
return
new
RSVP
.
Promise
(
function
(
resolve
,
reject
,
notify
)
{
fr
.
addEventListener
(
"
load
"
,
resolve
);
fr
.
addEventListener
(
"
error
"
,
reject
);
fr
.
addEventListener
(
"
progress
"
,
notify
);
fr
.
readAsArrayBuffer
(
blob
);
},
function
()
{
fr
.
abort
();
});
}
util
.
readBlobAsArrayBuffer
=
readBlobAsArrayBuffer
;
function
readBlobAsDataURL
(
blob
)
{
var
fr
=
new
FileReader
();
return
new
RSVP
.
Promise
(
function
(
resolve
,
reject
,
notify
)
{
fr
.
addEventListener
(
"
load
"
,
resolve
);
fr
.
addEventListener
(
"
error
"
,
reject
);
fr
.
addEventListener
(
"
progress
"
,
notify
);
fr
.
readAsDataURL
(
blob
);
},
function
()
{
fr
.
abort
();
});
}
util
.
readBlobAsDataURL
=
readBlobAsDataURL
;
function
stringify
(
obj
)
{
// Implement a stable JSON.stringify
// Object's keys are alphabetically ordered
var
key
,
key_list
,
i
,
value
,
result_list
;
if
(
obj
===
undefined
)
{
return
undefined
;
}
if
(
obj
.
constructor
===
Object
)
{
key_list
=
Object
.
keys
(
obj
).
sort
();
result_list
=
[];
for
(
i
=
0
;
i
<
key_list
.
length
;
i
+=
1
)
{
key
=
key_list
[
i
];
value
=
stringify
(
obj
[
key
]);
if
(
value
!==
undefined
)
{
result_list
.
push
(
stringify
(
key
)
+
'
:
'
+
value
);
}
}
return
'
{
'
+
result_list
.
join
(
'
,
'
)
+
'
}
'
;
}
if
(
obj
.
constructor
===
Array
)
{
result_list
=
[];
for
(
i
=
0
;
i
<
obj
.
length
;
i
+=
1
)
{
result_list
.
push
(
stringify
(
obj
[
i
]));
}
return
'
[
'
+
result_list
.
join
(
'
,
'
)
+
'
]
'
;
}
return
JSON
.
stringify
(
obj
);
}
util
.
stringify
=
stringify
;
// https://gist.github.com/davoclavo/4424731
function
dataURItoBlob
(
dataURI
)
{
if
(
dataURI
===
'
data:
'
)
{
return
new
Blob
();
}
// convert base64 to raw binary data held in a string
var
byteString
=
atob
(
dataURI
.
split
(
'
,
'
)[
1
]),
// separate out the mime component
mimeString
=
dataURI
.
split
(
'
,
'
)[
0
].
split
(
'
:
'
)[
1
],
// write the bytes of the string to an ArrayBuffer
arrayBuffer
=
new
ArrayBuffer
(
byteString
.
length
),
_ia
=
new
Uint8Array
(
arrayBuffer
),
i
;
mimeString
=
mimeString
.
slice
(
0
,
mimeString
.
length
-
"
;base64
"
.
length
);
for
(
i
=
0
;
i
<
byteString
.
length
;
i
+=
1
)
{
_ia
[
i
]
=
byteString
.
charCodeAt
(
i
);
}
return
new
Blob
([
arrayBuffer
],
{
type
:
mimeString
});
}
util
.
dataURItoBlob
=
dataURItoBlob
;
// tools
function
checkId
(
argument_list
,
storage
,
method_name
)
{
if
(
typeof
argument_list
[
0
]
!==
'
string
'
||
argument_list
[
0
]
===
''
)
{
throw
new
jIO
.
util
.
jIOError
(
"
Document id must be a non empty string on '
"
+
storage
.
__type
+
"
.
"
+
method_name
+
"
'.
"
,
400
);
}
}
function
checkAttachmentId
(
argument_list
,
storage
,
method_name
)
{
if
(
typeof
argument_list
[
1
]
!==
'
string
'
||
argument_list
[
1
]
===
''
)
{
throw
new
jIO
.
util
.
jIOError
(
"
Attachment id must be a non empty string on '
"
+
storage
.
__type
+
"
.
"
+
method_name
+
"
'.
"
,
400
);
}
}
function
declareMethod
(
klass
,
name
,
precondition_function
,
post_function
)
{
klass
.
prototype
[
name
]
=
function
()
{
var
argument_list
=
arguments
,
context
=
this
,
precondition_result
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
if
(
precondition_function
!==
undefined
)
{
return
precondition_function
.
apply
(
context
.
__storage
,
[
argument_list
,
context
,
name
]
);
}
})
.
push
(
function
(
result
)
{
var
storage_method
=
context
.
__storage
[
name
];
precondition_result
=
result
;
if
(
storage_method
===
undefined
)
{
throw
new
jIO
.
util
.
jIOError
(
"
Capacity '
"
+
name
+
"
' is not implemented on '
"
+
context
.
__type
+
"
'
"
,
501
);
}
return
storage_method
.
apply
(
context
.
__storage
,
argument_list
);
})
.
push
(
function
(
result
)
{
if
(
post_function
!==
undefined
)
{
return
post_function
.
call
(
context
,
argument_list
,
result
,
precondition_result
);
}
return
result
;
});
};
// Allow chain
return
this
;
}
/////////////////////////////////////////////////////////////////
// jIO Storage Proxy
/////////////////////////////////////////////////////////////////
function
JioProxyStorage
(
type
,
storage
)
{
if
(
!
(
this
instanceof
JioProxyStorage
))
{
return
new
JioProxyStorage
();
}
this
.
__type
=
type
;
this
.
__storage
=
storage
;
}
declareMethod
(
JioProxyStorage
,
"
put
"
,
checkId
,
function
(
argument_list
)
{
return
argument_list
[
0
];
});
declareMethod
(
JioProxyStorage
,
"
get
"
,
checkId
);
declareMethod
(
JioProxyStorage
,
"
bulk
"
);
declareMethod
(
JioProxyStorage
,
"
remove
"
,
checkId
,
function
(
argument_list
)
{
return
argument_list
[
0
];
});
JioProxyStorage
.
prototype
.
post
=
function
()
{
var
context
=
this
,
argument_list
=
arguments
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
var
storage_method
=
context
.
__storage
.
post
;
if
(
storage_method
===
undefined
)
{
throw
new
jIO
.
util
.
jIOError
(
"
Capacity 'post' is not implemented on '
"
+
context
.
__type
+
"
'
"
,
501
);
}
return
context
.
__storage
.
post
.
apply
(
context
.
__storage
,
argument_list
);
});
};
declareMethod
(
JioProxyStorage
,
'
putAttachment
'
,
function
(
argument_list
,
storage
,
method_name
)
{
checkId
(
argument_list
,
storage
,
method_name
);
checkAttachmentId
(
argument_list
,
storage
,
method_name
);
var
options
=
argument_list
[
3
]
||
{};
if
(
typeof
argument_list
[
2
]
===
'
string
'
)
{
argument_list
[
2
]
=
new
Blob
([
argument_list
[
2
]],
{
"
type
"
:
options
.
_content_type
||
options
.
_mimetype
||
"
text/plain;charset=utf-8
"
});
}
else
if
(
!
(
argument_list
[
2
]
instanceof
Blob
))
{
throw
new
jIO
.
util
.
jIOError
(
'
Attachment content is not a blob
'
,
400
);
}
});
declareMethod
(
JioProxyStorage
,
'
removeAttachment
'
,
function
(
argument_list
,
storage
,
method_name
)
{
checkId
(
argument_list
,
storage
,
method_name
);
checkAttachmentId
(
argument_list
,
storage
,
method_name
);
});
declareMethod
(
JioProxyStorage
,
'
getAttachment
'
,
function
(
argument_list
,
storage
,
method_name
)
{
var
result
=
"
blob
"
;
// if (param.storage_spec.type !== "indexeddb" &&
// param.storage_spec.type !== "dav" &&
// (param.kwargs._start !== undefined
// || param.kwargs._end !== undefined)) {
// restCommandRejecter(param, [
// 'bad_request',
// 'unsupport',
// '_start, _end not support'
// ]);
// return false;
// }
checkId
(
argument_list
,
storage
,
method_name
);
checkAttachmentId
(
argument_list
,
storage
,
method_name
);
// Drop optional parameters, which are only used in postfunction
if
(
argument_list
[
2
]
!==
undefined
)
{
result
=
argument_list
[
2
].
format
||
result
;
delete
argument_list
[
2
].
format
;
}
return
result
;
},
function
(
argument_list
,
blob
,
convert
)
{
var
result
;
if
(
!
(
blob
instanceof
Blob
))
{
throw
new
jIO
.
util
.
jIOError
(
"
'getAttachment' (
"
+
argument_list
[
0
]
+
"
,
"
+
argument_list
[
1
]
+
"
) on '
"
+
this
.
__type
+
"
' does not return a Blob.
"
,
501
);
}
if
(
convert
===
"
blob
"
)
{
result
=
blob
;
}
else
if
(
convert
===
"
data_url
"
)
{
result
=
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
jIO
.
util
.
readBlobAsDataURL
(
blob
);
})
.
push
(
function
(
evt
)
{
return
evt
.
target
.
result
;
});
}
else
if
(
convert
===
"
array_buffer
"
)
{
result
=
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
jIO
.
util
.
readBlobAsArrayBuffer
(
blob
);
})
.
push
(
function
(
evt
)
{
return
evt
.
target
.
result
;
});
}
else
if
(
convert
===
"
text
"
)
{
result
=
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
jIO
.
util
.
readBlobAsText
(
blob
);
})
.
push
(
function
(
evt
)
{
return
evt
.
target
.
result
;
});
}
else
if
(
convert
===
"
json
"
)
{
result
=
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
jIO
.
util
.
readBlobAsText
(
blob
);
})
.
push
(
function
(
evt
)
{
return
JSON
.
parse
(
evt
.
target
.
result
);
});
}
else
{
throw
new
jIO
.
util
.
jIOError
(
this
.
__type
+
"
.getAttachment format: '
"
+
convert
+
"
' is not supported
"
,
400
);
}
return
result
;
});
JioProxyStorage
.
prototype
.
buildQuery
=
function
()
{
var
storage_method
=
this
.
__storage
.
buildQuery
,
context
=
this
,
argument_list
=
arguments
;
if
(
storage_method
===
undefined
)
{
throw
new
jIO
.
util
.
jIOError
(
"
Capacity 'buildQuery' is not implemented on '
"
+
this
.
__type
+
"
'
"
,
501
);
}
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
storage_method
.
apply
(
context
.
__storage
,
argument_list
);
});
};
JioProxyStorage
.
prototype
.
hasCapacity
=
function
(
name
)
{
var
storage_method
=
this
.
__storage
.
hasCapacity
,
capacity_method
=
this
.
__storage
[
name
];
if
(
capacity_method
!==
undefined
)
{
return
true
;
}
if
((
storage_method
===
undefined
)
||
!
storage_method
.
apply
(
this
.
__storage
,
arguments
))
{
throw
new
jIO
.
util
.
jIOError
(
"
Capacity '
"
+
name
+
"
' is not implemented on '
"
+
this
.
__type
+
"
'
"
,
501
);
}
return
true
;
};
JioProxyStorage
.
prototype
.
allDocs
=
function
(
options
)
{
var
context
=
this
;
if
(
options
===
undefined
)
{
options
=
{};
}
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
if
(
context
.
hasCapacity
(
"
list
"
)
&&
((
options
.
query
===
undefined
)
||
context
.
hasCapacity
(
"
query
"
))
&&
((
options
.
sort_on
===
undefined
)
||
context
.
hasCapacity
(
"
sort
"
))
&&
((
options
.
select_list
===
undefined
)
||
context
.
hasCapacity
(
"
select
"
))
&&
((
options
.
include_docs
===
undefined
)
||
context
.
hasCapacity
(
"
include
"
))
&&
((
options
.
limit
===
undefined
)
||
context
.
hasCapacity
(
"
limit
"
)))
{
return
context
.
buildQuery
(
options
);
}
})
.
push
(
function
(
result
)
{
return
{
data
:
{
rows
:
result
,
total_rows
:
result
.
length
}
};
});
};
declareMethod
(
JioProxyStorage
,
"
allAttachments
"
,
checkId
);
declareMethod
(
JioProxyStorage
,
"
repair
"
);
JioProxyStorage
.
prototype
.
repair
=
function
()
{
var
context
=
this
,
argument_list
=
arguments
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
var
storage_method
=
context
.
__storage
.
repair
;
if
(
storage_method
!==
undefined
)
{
return
context
.
__storage
.
repair
.
apply
(
context
.
__storage
,
argument_list
);
}
});
};
/////////////////////////////////////////////////////////////////
// Storage builder
/////////////////////////////////////////////////////////////////
function
JioBuilder
()
{
if
(
!
(
this
instanceof
JioBuilder
))
{
return
new
JioBuilder
();
}
this
.
__storage_types
=
{};
}
JioBuilder
.
prototype
.
createJIO
=
function
(
storage_spec
,
util
)
{
if
(
typeof
storage_spec
.
type
!==
'
string
'
)
{
throw
new
TypeError
(
"
Invalid storage description
"
);
}
if
(
!
this
.
__storage_types
[
storage_spec
.
type
])
{
throw
new
TypeError
(
"
Unknown storage '
"
+
storage_spec
.
type
+
"
'
"
);
}
return
new
JioProxyStorage
(
storage_spec
.
type
,
new
this
.
__storage_types
[
storage_spec
.
type
](
storage_spec
,
util
)
);
};
JioBuilder
.
prototype
.
addStorage
=
function
(
type
,
Constructor
)
{
if
(
typeof
type
!==
'
string
'
)
{
throw
new
TypeError
(
"
jIO.addStorage(): Argument 1 is not of type 'string'
"
);
}
if
(
typeof
Constructor
!==
'
function
'
)
{
throw
new
TypeError
(
"
jIO.addStorage():
"
+
"
Argument 2 is not of type 'function'
"
);
}
if
(
this
.
__storage_types
[
type
]
!==
undefined
)
{
throw
new
TypeError
(
"
jIO.addStorage(): Storage type already exists
"
);
}
this
.
__storage_types
[
type
]
=
Constructor
;
};
JioBuilder
.
prototype
.
util
=
util
;
JioBuilder
.
prototype
.
QueryFactory
=
QueryFactory
;
JioBuilder
.
prototype
.
Query
=
Query
;
/////////////////////////////////////////////////////////////////
// global
/////////////////////////////////////////////////////////////////
jIO
=
new
JioBuilder
();
window
.
jIO
=
jIO
;
}(
window
,
RSVP
,
Blob
,
QueryFactory
,
Query
,
atob
,
FileReader
,
ArrayBuffer
,
Uint8Array
,
navigator
));
src/jio.js
View file @
114045eb
/*global window, RSVP, Blob, XMLHttpRequest, QueryFactory, Query, atob,
FileReader, ArrayBuffer, Uint8Array, navigator
, FormData, StreamBuffers
*/
FileReader, ArrayBuffer, Uint8Array, navigator */
(
function
(
window
,
RSVP
,
Blob
,
QueryFactory
,
Query
,
atob
,
FileReader
,
ArrayBuffer
,
Uint8Array
,
navigator
)
{
"
use strict
"
;
...
...
@@ -47,7 +47,7 @@
function
ajax
(
param
)
{
var
xhr
=
new
XMLHttpRequest
();
return
new
RSVP
.
Promise
(
function
(
resolve
,
reject
,
notify
)
{
var
k
,
buffer
=
new
StreamBuffers
.
WritableStreamBuffer
()
;
var
k
;
xhr
.
open
(
param
.
type
||
"
GET
"
,
param
.
url
,
true
);
xhr
.
responseType
=
param
.
dataType
||
""
;
if
(
typeof
param
.
headers
===
'
object
'
&&
param
.
headers
!==
null
)
{
...
...
@@ -57,7 +57,6 @@
}
}
}
xhr
.
setRequestHeader
(
"
Accept
"
,
"
*/*
"
);
xhr
.
addEventListener
(
"
load
"
,
function
(
e
)
{
if
(
e
.
target
.
status
>=
400
)
{
return
reject
(
e
);
...
...
@@ -76,14 +75,7 @@
if
(
typeof
param
.
beforeSend
===
'
function
'
)
{
param
.
beforeSend
(
xhr
);
}
if
(
param
.
data
instanceof
FormData
)
{
xhr
.
setRequestHeader
(
"
Content-Type
"
,
"
multipart
\
/form-data; boundary=
"
+
param
.
data
.
getBoundary
());
param
.
data
.
pipe
(
buffer
);
xhr
.
send
(
buffer
.
getContents
());
}
else
{
xhr
.
send
(
param
.
data
);
}
xhr
.
send
(
param
.
data
);
},
function
()
{
xhr
.
abort
();
});
...
...
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