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
Alain Takoudjou
jio
Commits
1b3203be
Commit
1b3203be
authored
Mar 27, 2015
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add UuidStorage to generate new id when calling jio.post
parent
c287286c
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
448 additions
and
69 deletions
+448
-69
Gruntfile.js
Gruntfile.js
+1
-0
src/jio.js
src/jio.js
+17
-25
src/jio.storage/uuidstorage.js
src/jio.storage/uuidstorage.js
+60
-0
test/jio.storage/unionstorage.tests.js
test/jio.storage/unionstorage.tests.js
+3
-3
test/jio.storage/uuidstorage.tests.js
test/jio.storage/uuidstorage.tests.js
+366
-0
test/jio/util.js
test/jio/util.js
+0
-41
test/tests.html
test/tests.html
+1
-0
No files found.
Gruntfile.js
View file @
1b3203be
...
...
@@ -171,6 +171,7 @@ module.exports = function (grunt) {
'
src/jio.js
'
,
'
src/jio.storage/uuidstorage.js
'
,
'
src/jio.storage/memorystorage.js
'
,
'
src/jio.storage/localstorage.js
'
,
'
src/jio.storage/davstorage.js
'
,
...
...
src/jio.js
View file @
1b3203be
...
...
@@ -131,25 +131,6 @@
}
util
.
deepClone
=
deepClone
;
/**
* An Universal Unique ID generator
*
* @return {String} The new UUID.
*/
function
generateUuid
()
{
function
S4
()
{
return
(
'
0000
'
+
Math
.
floor
(
Math
.
random
()
*
0x10000
/* 65536 */
).
toString
(
16
)).
slice
(
-
4
);
}
return
S4
()
+
S4
()
+
"
-
"
+
S4
()
+
"
-
"
+
S4
()
+
"
-
"
+
S4
()
+
"
-
"
+
S4
()
+
S4
()
+
S4
();
}
util
.
generateUuid
=
generateUuid
;
function
readBlobAsText
(
blob
,
encoding
)
{
...
...
@@ -326,12 +307,23 @@
return
argument_list
[
0
].
_id
;
});
// listeners
declareMethod
(
JioProxyStorage
,
"
post
"
,
function
(
param
,
storage
,
method_name
)
{
if
(
param
.
_id
!==
undefined
)
{
return
checkId
(
param
,
storage
,
method_name
);
}
});
JioProxyStorage
.
prototype
.
post
=
function
(
param
)
{
var
context
=
this
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
if
(
param
.
_id
===
undefined
)
{
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
(
param
);
}
return
context
.
put
(
param
);
});
};
declareMethod
(
JioProxyStorage
,
'
putAttachment
'
,
function
(
param
,
storage
,
method_name
)
{
checkId
(
param
,
storage
,
method_name
);
...
...
src/jio.storage/uuidstorage.js
0 → 100644
View file @
1b3203be
/*jslint nomen: true*/
(
function
(
jIO
)
{
"
use strict
"
;
/**
* The jIO UUIDStorage extension
*
* @class UUIDStorage
* @constructor
*/
function
UUIDStorage
(
spec
)
{
this
.
_sub_storage
=
jIO
.
createJIO
(
spec
.
sub_storage
);
}
UUIDStorage
.
prototype
.
get
=
function
()
{
return
this
.
_sub_storage
.
get
.
apply
(
this
.
_sub_storage
,
arguments
);
};
UUIDStorage
.
prototype
.
post
=
function
(
param
)
{
function
S4
()
{
return
(
'
0000
'
+
Math
.
floor
(
Math
.
random
()
*
0x10000
/* 65536 */
).
toString
(
16
)).
slice
(
-
4
);
}
param
.
_id
=
S4
()
+
S4
()
+
"
-
"
+
S4
()
+
"
-
"
+
S4
()
+
"
-
"
+
S4
()
+
"
-
"
+
S4
()
+
S4
()
+
S4
();
return
this
.
put
(
param
);
};
UUIDStorage
.
prototype
.
put
=
function
()
{
return
this
.
_sub_storage
.
put
.
apply
(
this
.
_sub_storage
,
arguments
);
};
UUIDStorage
.
prototype
.
remove
=
function
()
{
return
this
.
_sub_storage
.
remove
.
apply
(
this
.
_sub_storage
,
arguments
);
};
UUIDStorage
.
prototype
.
getAttachment
=
function
()
{
return
this
.
_sub_storage
.
getAttachment
.
apply
(
this
.
_sub_storage
,
arguments
);
};
UUIDStorage
.
prototype
.
putAttachment
=
function
()
{
return
this
.
_sub_storage
.
putAttachment
.
apply
(
this
.
_sub_storage
,
arguments
);
};
UUIDStorage
.
prototype
.
removeAttachment
=
function
()
{
return
this
.
_sub_storage
.
removeAttachment
.
apply
(
this
.
_sub_storage
,
arguments
);
};
UUIDStorage
.
prototype
.
hasCapacity
=
function
(
name
)
{
return
this
.
_sub_storage
.
hasCapacity
(
name
);
};
UUIDStorage
.
prototype
.
buildQuery
=
function
()
{
return
this
.
_sub_storage
.
buildQuery
.
apply
(
this
.
_sub_storage
,
arguments
);
};
jIO
.
addStorage
(
'
uuid
'
,
UUIDStorage
);
}(
jIO
));
test/jio.storage/unionstorage.tests.js
View file @
1b3203be
...
...
@@ -40,8 +40,8 @@
return
param
.
_id
;
};
Storage200
.
prototype
.
post
=
function
(
param
)
{
deepEqual
(
param
,
{
"
_id
"
:
"
bar
"
,
"
title
"
:
"
foo
"
},
"
post 200 called
"
);
return
param
.
_id
;
deepEqual
(
param
,
{
"
title
"
:
"
foo
"
},
"
post 200 called
"
);
return
"
bar
"
;
};
Storage200
.
prototype
.
hasCapacity
=
function
()
{
return
true
;
...
...
@@ -302,7 +302,7 @@
}]
});
jio
.
post
({
"
_id
"
:
"
bar
"
,
"
title
"
:
"
foo
"
})
jio
.
post
({
"
title
"
:
"
foo
"
})
.
then
(
function
(
result
)
{
equal
(
result
,
"
bar
"
);
})
...
...
test/jio.storage/uuidstorage.tests.js
0 → 100644
View file @
1b3203be
/*jslint nomen: true*/
/*global Blob*/
(
function
(
jIO
,
QUnit
,
Blob
)
{
"
use strict
"
;
var
test
=
QUnit
.
test
,
stop
=
QUnit
.
stop
,
start
=
QUnit
.
start
,
ok
=
QUnit
.
ok
,
expect
=
QUnit
.
expect
,
deepEqual
=
QUnit
.
deepEqual
,
equal
=
QUnit
.
equal
,
module
=
QUnit
.
module
,
throws
=
QUnit
.
throws
;
/////////////////////////////////////////////////////////////////
// Custom test substorage definition
/////////////////////////////////////////////////////////////////
function
Storage200
()
{
return
this
;
}
jIO
.
addStorage
(
'
uuidstorage200
'
,
Storage200
);
/////////////////////////////////////////////////////////////////
// uuidStorage.constructor
/////////////////////////////////////////////////////////////////
module
(
"
uuidStorage.constructor
"
);
test
(
"
create substorage
"
,
function
()
{
var
jio
=
jIO
.
createJIO
({
type
:
"
uuid
"
,
sub_storage
:
{
type
:
"
uuidstorage200
"
}
});
ok
(
jio
.
__storage
.
_sub_storage
instanceof
jio
.
constructor
);
equal
(
jio
.
__storage
.
_sub_storage
.
__type
,
"
uuidstorage200
"
);
});
/////////////////////////////////////////////////////////////////
// uuidStorage.get
/////////////////////////////////////////////////////////////////
module
(
"
uuidStorage.get
"
);
test
(
"
get called substorage get
"
,
function
()
{
stop
();
expect
(
2
);
var
jio
=
jIO
.
createJIO
({
type
:
"
uuid
"
,
sub_storage
:
{
type
:
"
uuidstorage200
"
}
});
Storage200
.
prototype
.
get
=
function
(
param
)
{
equal
(
param
.
_id
,
"
bar
"
,
"
get 200 called
"
);
return
{
title
:
"
foo
"
};
};
jio
.
get
({
"
_id
"
:
"
bar
"
})
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{
"
_id
"
:
"
bar
"
,
"
title
"
:
"
foo
"
},
"
Check document
"
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
/////////////////////////////////////////////////////////////////
// uuidStorage.post
/////////////////////////////////////////////////////////////////
module
(
"
uuidStorage.post
"
);
test
(
"
post called substorage put with a new id
"
,
function
()
{
stop
();
expect
(
3
);
var
jio
=
jIO
.
createJIO
({
type
:
"
uuid
"
,
sub_storage
:
{
type
:
"
uuidstorage200
"
}
}),
uuid
;
function
isUuid
(
uuid
)
{
var
x
=
"
[0-9a-fA-F]
"
;
if
(
typeof
uuid
!==
"
string
"
)
{
return
false
;
}
return
(
uuid
.
match
(
"
^
"
+
x
+
"
{8}-
"
+
x
+
"
{4}-
"
+
x
+
"
{4}-
"
+
x
+
"
{4}-
"
+
x
+
"
{12}$
"
)
===
null
?
false
:
true
);
}
Storage200
.
prototype
.
put
=
function
(
param
)
{
uuid
=
param
.
_id
;
deepEqual
(
param
,
{
"
_id
"
:
uuid
,
"
title
"
:
"
foo
"
},
"
post 200 called
"
);
return
"
bar
"
;
};
jio
.
post
({
"
title
"
:
"
foo
"
})
.
then
(
function
(
result
)
{
equal
(
result
,
uuid
);
ok
(
isUuid
(
uuid
),
uuid
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
/////////////////////////////////////////////////////////////////
// uuidStorage.put
/////////////////////////////////////////////////////////////////
module
(
"
uuidStorage.put
"
);
test
(
"
put called substorage put
"
,
function
()
{
stop
();
expect
(
2
);
var
jio
=
jIO
.
createJIO
({
type
:
"
uuid
"
,
sub_storage
:
{
type
:
"
uuidstorage200
"
}
});
Storage200
.
prototype
.
put
=
function
(
param
)
{
deepEqual
(
param
,
{
"
_id
"
:
"
bar
"
,
"
title
"
:
"
foo
"
},
"
put 200 called
"
);
return
param
.
_id
;
};
jio
.
put
({
"
_id
"
:
"
bar
"
,
"
title
"
:
"
foo
"
})
.
then
(
function
(
result
)
{
equal
(
result
,
"
bar
"
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
/////////////////////////////////////////////////////////////////
// uuidStorage.remove
/////////////////////////////////////////////////////////////////
module
(
"
uuidStorage.remove
"
);
test
(
"
remove called substorage remove
"
,
function
()
{
stop
();
expect
(
2
);
var
jio
=
jIO
.
createJIO
({
type
:
"
uuid
"
,
sub_storage
:
{
type
:
"
uuidstorage200
"
}
});
Storage200
.
prototype
.
remove
=
function
(
param
)
{
deepEqual
(
param
,
{
"
_id
"
:
"
bar
"
},
"
remove 200 called
"
);
return
param
.
_id
;
};
jio
.
remove
({
"
_id
"
:
"
bar
"
})
.
then
(
function
(
result
)
{
equal
(
result
,
"
bar
"
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
/////////////////////////////////////////////////////////////////
// uuidStorage.getAttachment
/////////////////////////////////////////////////////////////////
module
(
"
uuidStorage.getAttachment
"
);
test
(
"
getAttachment called substorage getAttachment
"
,
function
()
{
stop
();
expect
(
2
);
var
jio
=
jIO
.
createJIO
({
type
:
"
uuid
"
,
sub_storage
:
{
type
:
"
uuidstorage200
"
}
}),
blob
=
new
Blob
([
""
]);
Storage200
.
prototype
.
getAttachment
=
function
(
param
)
{
deepEqual
(
param
,
{
"
_id
"
:
"
bar
"
,
"
_attachment
"
:
"
foo
"
},
"
getAttachment 200 called
"
);
return
{
data
:
blob
};
};
jio
.
getAttachment
({
"
_id
"
:
"
bar
"
,
"
_attachment
"
:
"
foo
"
})
.
then
(
function
(
result
)
{
equal
(
result
.
data
,
blob
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
/////////////////////////////////////////////////////////////////
// uuidStorage.putAttachment
/////////////////////////////////////////////////////////////////
module
(
"
uuidStorage.putAttachment
"
);
test
(
"
putAttachment called substorage putAttachment
"
,
function
()
{
stop
();
expect
(
2
);
var
jio
=
jIO
.
createJIO
({
type
:
"
uuid
"
,
sub_storage
:
{
type
:
"
uuidstorage200
"
}
}),
blob
=
new
Blob
([
""
]);
Storage200
.
prototype
.
putAttachment
=
function
(
param
)
{
deepEqual
(
param
,
{
"
_id
"
:
"
bar
"
,
"
_attachment
"
:
"
foo
"
,
"
_blob
"
:
blob
},
"
putAttachment 200 called
"
);
return
"
OK
"
;
};
jio
.
putAttachment
({
"
_id
"
:
"
bar
"
,
"
_attachment
"
:
"
foo
"
,
"
_blob
"
:
blob
})
.
then
(
function
(
result
)
{
equal
(
result
,
"
OK
"
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
/////////////////////////////////////////////////////////////////
// uuidStorage.removeAttachment
/////////////////////////////////////////////////////////////////
module
(
"
uuidStorage.removeAttachment
"
);
test
(
"
removeAttachment called substorage removeAttachment
"
,
function
()
{
stop
();
expect
(
2
);
var
jio
=
jIO
.
createJIO
({
type
:
"
uuid
"
,
sub_storage
:
{
type
:
"
uuidstorage200
"
}
});
Storage200
.
prototype
.
removeAttachment
=
function
(
param
)
{
deepEqual
(
param
,
{
"
_id
"
:
"
bar
"
,
"
_attachment
"
:
"
foo
"
},
"
removeAttachment 200 called
"
);
return
"
Removed
"
;
};
jio
.
removeAttachment
({
"
_id
"
:
"
bar
"
,
"
_attachment
"
:
"
foo
"
})
.
then
(
function
(
result
)
{
equal
(
result
,
"
Removed
"
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
/////////////////////////////////////////////////////////////////
// uuidStorage.hasCapacity
/////////////////////////////////////////////////////////////////
module
(
"
uuidStorage.hasCapacity
"
);
test
(
"
hasCapacity return substorage value
"
,
function
()
{
var
jio
=
jIO
.
createJIO
({
type
:
"
uuid
"
,
sub_storage
:
{
type
:
"
uuidstorage200
"
}
});
delete
Storage200
.
prototype
.
hasCapacity
;
throws
(
function
()
{
jio
.
hasCapacity
(
"
foo
"
);
},
function
(
error
)
{
ok
(
error
instanceof
jIO
.
util
.
jIOError
);
equal
(
error
.
status_code
,
501
);
equal
(
error
.
message
,
"
Capacity 'foo' is not implemented on 'uuidstorage200'
"
);
return
true
;
}
);
});
/////////////////////////////////////////////////////////////////
// uuidStorage.buildQuery
/////////////////////////////////////////////////////////////////
module
(
"
uuidStorage.buildQuery
"
);
test
(
"
buildQuery return substorage buildQuery
"
,
function
()
{
stop
();
expect
(
2
);
var
jio
=
jIO
.
createJIO
({
type
:
"
uuid
"
,
sub_storage
:
{
type
:
"
uuidstorage200
"
}
});
Storage200
.
prototype
.
hasCapacity
=
function
()
{
return
true
;
};
Storage200
.
prototype
.
buildQuery
=
function
(
options
)
{
deepEqual
(
options
,
{
include_docs
:
false
,
sort_on
:
[[
"
title
"
,
"
ascending
"
]],
limit
:
[
5
],
select_list
:
[
"
title
"
,
"
id
"
],
uuid
:
'
title: "two"
'
},
"
allDocs parameter
"
);
return
"
bar
"
;
};
jio
.
allDocs
({
include_docs
:
false
,
sort_on
:
[[
"
title
"
,
"
ascending
"
]],
limit
:
[
5
],
select_list
:
[
"
title
"
,
"
id
"
],
uuid
:
'
title: "two"
'
})
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{
data
:
{
rows
:
"
bar
"
,
total_rows
:
3
}
});
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
}(
jIO
,
QUnit
,
Blob
));
test/jio/util.js
deleted
100644 → 0
View file @
c287286c
/*jslint indent: 2, maxlen: 80 */
/*global define, exports, window, require, localStorage, start, ok, deepEqual,
sinon, setTimeout, clearTimeout */
(
function
(
dependencies
,
module
)
{
"
use strict
"
;
if
(
typeof
define
===
'
function
'
&&
define
.
amd
)
{
return
define
(
dependencies
,
module
);
}
if
(
typeof
exports
===
'
object
'
)
{
module
(
exports
,
require
(
'
sinon_qunit
'
));
}
if
(
typeof
window
===
'
object
'
)
{
window
.
test_util
=
{};
module
(
window
.
test_util
);
}
}([
'
exports
'
,
'
sinon_qunit
'
],
function
(
exports
)
{
"
use strict
"
;
//////////////////////////////////////////////////////////////////////////////
// Tools
/**
* Test if the string is an Uuid
*
* @param {String} uuid The string to test
* @return {Boolean} true if is uuid, else false
*/
function
isUuid
(
uuid
)
{
var
x
=
"
[0-9a-fA-F]
"
;
if
(
typeof
uuid
!==
"
string
"
)
{
return
false
;
}
return
(
uuid
.
match
(
"
^
"
+
x
+
"
{8}-
"
+
x
+
"
{4}-
"
+
x
+
"
{4}-
"
+
x
+
"
{4}-
"
+
x
+
"
{12}$
"
)
===
null
?
false
:
true
);
}
exports
.
isUuid
=
isUuid
;
}));
test/tests.html
View file @
1b3203be
...
...
@@ -37,6 +37,7 @@
<script
src=
"jio.storage/unionstorage.tests.js"
></script>
<script
src=
"jio.storage/erp5storage.tests.js"
></script>
<script
src=
"jio.storage/indexeddbstorage.tests.js"
></script>
<script
src=
"jio.storage/uuidstorage.tests.js"
></script>
<!--script src="jio.storage/indexstorage.tests.js"></script-->
<!--script src="jio.storage/dropboxstorage.tests.js"></script-->
...
...
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