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
Labels
Merge Requests
18
Merge Requests
18
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
jio
Commits
98d10707
Commit
98d10707
authored
Feb 20, 2019
by
preetwinder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use jio storage for ids
parent
c4642dac
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
97 additions
and
22 deletions
+97
-22
examples/scenario.js
examples/scenario.js
+11
-2
src/jio.storage/liststorage.js
src/jio.storage/liststorage.js
+17
-12
test/jio.storage/liststorage.tests.js
test/jio.storage/liststorage.tests.js
+69
-8
No files found.
examples/scenario.js
View file @
98d10707
...
@@ -18,7 +18,7 @@
...
@@ -18,7 +18,7 @@
* See https://www.nexedi.com/licensing for rationale and options.
* See https://www.nexedi.com/licensing for rationale and options.
*/
*/
/*global console, btoa, Blob*/
/*global console, btoa, Blob
, indexedDB
*/
/*jslint nomen: true, maxlen: 200*/
/*jslint nomen: true, maxlen: 200*/
(
function
(
window
,
QUnit
,
jIO
,
rJS
)
{
(
function
(
window
,
QUnit
,
jIO
,
rJS
)
{
"
use strict
"
;
"
use strict
"
;
...
@@ -28,7 +28,9 @@
...
@@ -28,7 +28,9 @@
ok
=
QUnit
.
ok
,
ok
=
QUnit
.
ok
,
stop
=
QUnit
.
stop
,
stop
=
QUnit
.
stop
,
start
=
QUnit
.
start
,
start
=
QUnit
.
start
,
deepEqual
=
QUnit
.
deepEqual
;
deepEqual
=
QUnit
.
deepEqual
,
test_signature_database
=
'
test_signature_storage_scenario
'
;
rJS
(
window
)
rJS
(
window
)
...
@@ -61,6 +63,10 @@
...
@@ -61,6 +63,10 @@
type
:
"
query
"
,
type
:
"
query
"
,
sub_storage
:
{
sub_storage
:
{
type
:
"
list
"
,
type
:
"
list
"
,
signature_storage
:
{
type
:
"
indexeddb
"
,
database
:
test_signature_database
},
sub_storage
:
{
sub_storage
:
{
type
:
"
nocapacity
"
,
type
:
"
nocapacity
"
,
sub_storage
:
{
sub_storage
:
{
...
@@ -368,6 +374,9 @@
...
@@ -368,6 +374,9 @@
.
then
(
function
()
{
.
then
(
function
()
{
return
jio
.
repair
();
return
jio
.
repair
();
})
})
.
then
(
function
()
{
return
indexedDB
.
deleteDatabase
(
'
jio:
'
+
test_signature_database
);
})
.
fail
(
function
(
error
)
{
.
fail
(
function
(
error
)
{
console
.
error
(
"
---
"
);
console
.
error
(
"
---
"
);
...
...
src/jio.storage/liststorage.js
View file @
98d10707
...
@@ -24,7 +24,7 @@
...
@@ -24,7 +24,7 @@
function
ListStorage
(
spec
)
{
function
ListStorage
(
spec
)
{
this
.
_sub_storage
=
jIO
.
createJIO
(
spec
.
sub_storage
);
this
.
_sub_storage
=
jIO
.
createJIO
(
spec
.
sub_storage
);
this
.
_s
ub_storage_index
=
new
Set
(
);
this
.
_s
ignature_storage
=
jIO
.
createJIO
(
spec
.
signature_storage
);
}
}
ListStorage
.
prototype
.
get
=
function
()
{
ListStorage
.
prototype
.
get
=
function
()
{
...
@@ -37,24 +37,30 @@
...
@@ -37,24 +37,30 @@
var
gadget
=
this
;
var
gadget
=
this
;
return
gadget
.
_sub_storage
.
post
(
value
)
return
gadget
.
_sub_storage
.
post
(
value
)
.
push
(
function
(
id
)
{
.
push
(
function
(
id
)
{
gadget
.
_sub_storage_index
.
add
(
id
);
return
gadget
.
_signature_storage
.
put
(
id
,
{
"
id
"
:
id
})
return
id
;
.
push
(
function
()
{
return
id
;
});
});
});
};
};
ListStorage
.
prototype
.
put
=
function
(
id
,
value
)
{
ListStorage
.
prototype
.
put
=
function
(
id
,
value
)
{
var
gadget
=
this
;
var
gadget
=
this
;
return
gadget
.
_sub_storage
.
put
(
id
,
value
)
return
gadget
.
_sub_storage
.
put
(
id
,
value
)
.
push
(
function
(
result
)
{
.
push
(
function
(
result
)
{
gadget
.
_sub_storage_index
.
add
(
id
);
return
gadget
.
_signature_storage
.
put
(
id
,
{
"
id
"
:
id
})
return
result
;
.
push
(
function
()
{
return
result
;
});
});
});
};
};
ListStorage
.
prototype
.
remove
=
function
(
id
)
{
ListStorage
.
prototype
.
remove
=
function
(
id
)
{
var
gadget
=
this
;
var
gadget
=
this
;
return
gadget
.
_sub_storage
.
remove
(
id
)
return
gadget
.
_sub_storage
.
remove
(
id
)
.
push
(
function
(
result
)
{
.
push
(
function
(
result
)
{
gadget
.
_sub_storage_index
.
delete
(
id
);
return
gadget
.
_signature_storage
.
remove
(
id
)
return
result
;
.
push
(
function
()
{
return
result
;
});
});
});
};
};
ListStorage
.
prototype
.
getAttachment
=
function
()
{
ListStorage
.
prototype
.
getAttachment
=
function
()
{
...
@@ -76,11 +82,10 @@
...
@@ -76,11 +82,10 @@
}
}
};
};
ListStorage
.
prototype
.
buildQuery
=
function
()
{
ListStorage
.
prototype
.
buildQuery
=
function
()
{
var
rows
=
[],
i
,
ids
=
Array
.
from
(
this
.
_sub_storage_index
);
return
this
.
_signature_storage
.
buildQuery
({})
for
(
i
=
0
;
i
<
ids
.
length
;
i
+=
1
)
{
.
push
(
function
(
result
)
{
rows
.
push
({
id
:
ids
[
i
],
value
:
{}});
return
result
;
}
});
return
rows
;
};
};
jIO
.
addStorage
(
'
list
'
,
ListStorage
);
jIO
.
addStorage
(
'
list
'
,
ListStorage
);
...
...
test/jio.storage/liststorage.tests.js
View file @
98d10707
...
@@ -18,7 +18,7 @@
...
@@ -18,7 +18,7 @@
* See https://www.nexedi.com/licensing for rationale and options.
* See https://www.nexedi.com/licensing for rationale and options.
*/
*/
/*jslint nomen: true */
/*jslint nomen: true */
/*global Blob*/
/*global Blob
, indexedDB
*/
(
function
(
jIO
,
QUnit
)
{
(
function
(
jIO
,
QUnit
)
{
"
use strict
"
;
"
use strict
"
;
var
test
=
QUnit
.
test
,
var
test
=
QUnit
.
test
,
...
@@ -28,7 +28,8 @@
...
@@ -28,7 +28,8 @@
ok
=
QUnit
.
ok
,
ok
=
QUnit
.
ok
,
start
=
QUnit
.
start
,
start
=
QUnit
.
start
,
equal
=
QUnit
.
equal
,
equal
=
QUnit
.
equal
,
module
=
QUnit
.
module
;
module
=
QUnit
.
module
,
test_signature_database
=
'
test_signature_storage
'
;
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
// Custom test substorage definition
// Custom test substorage definition
...
@@ -42,18 +43,24 @@
...
@@ -42,18 +43,24 @@
// ListStorage constructor
// ListStorage constructor
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
module
(
"
ListStorage.constructor
"
);
module
(
"
ListStorage.constructor
"
);
test
(
"
create storage
"
,
function
()
{
test
(
"
create storage
"
,
function
()
{
var
jio
=
jIO
.
createJIO
({
var
jio
=
jIO
.
createJIO
({
type
:
"
list
"
,
type
:
"
list
"
,
signature_storage
:
{
type
:
"
indexeddb
"
,
database
:
test_signature_database
},
sub_storage
:
{
sub_storage
:
{
type
:
"
dummystorage1
"
type
:
"
dummystorage1
"
}
}
});
});
equal
(
jio
.
__type
,
"
list
"
);
equal
(
jio
.
__type
,
"
list
"
);
equal
(
jio
.
__storage
.
_sub_storage
.
__type
,
"
dummystorage1
"
);
equal
(
jio
.
__storage
.
_sub_storage
.
__type
,
"
dummystorage1
"
);
equal
(
jio
.
__storage
.
_sub_storage_index
.
constructor
.
name
,
"
Set
"
);
equal
(
jio
.
__storage
.
_signature_storage
.
__type
,
"
indexeddb
"
);
indexedDB
.
deleteDatabase
(
'
jio:
'
+
test_signature_database
);
});
});
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
...
@@ -68,6 +75,10 @@
...
@@ -68,6 +75,10 @@
var
jio
=
jIO
.
createJIO
({
var
jio
=
jIO
.
createJIO
({
type
:
"
list
"
,
type
:
"
list
"
,
signature_storage
:
{
type
:
"
indexeddb
"
,
database
:
test_signature_database
},
sub_storage
:
{
sub_storage
:
{
type
:
"
dummystorage1
"
type
:
"
dummystorage1
"
}
}
...
@@ -88,6 +99,7 @@
...
@@ -88,6 +99,7 @@
ok
(
false
,
error
);
ok
(
false
,
error
);
})
})
.
always
(
function
()
{
.
always
(
function
()
{
indexedDB
.
deleteDatabase
(
'
jio:
'
+
test_signature_database
);
start
();
start
();
});
});
});
});
...
@@ -102,6 +114,10 @@
...
@@ -102,6 +114,10 @@
var
jio
=
jIO
.
createJIO
({
var
jio
=
jIO
.
createJIO
({
type
:
"
list
"
,
type
:
"
list
"
,
signature_storage
:
{
type
:
"
indexeddb
"
,
database
:
test_signature_database
},
sub_storage
:
{
sub_storage
:
{
type
:
"
dummystorage1
"
type
:
"
dummystorage1
"
}
}
...
@@ -122,6 +138,7 @@
...
@@ -122,6 +138,7 @@
ok
(
false
,
error
);
ok
(
false
,
error
);
})
})
.
always
(
function
()
{
.
always
(
function
()
{
indexedDB
.
deleteDatabase
(
'
jio:
'
+
test_signature_database
);
start
();
start
();
});
});
});
});
...
@@ -136,6 +153,10 @@
...
@@ -136,6 +153,10 @@
var
jio
=
jIO
.
createJIO
({
var
jio
=
jIO
.
createJIO
({
type
:
"
list
"
,
type
:
"
list
"
,
signature_storage
:
{
type
:
"
indexeddb
"
,
database
:
test_signature_database
},
sub_storage
:
{
sub_storage
:
{
type
:
"
dummystorage1
"
type
:
"
dummystorage1
"
}
}
...
@@ -149,12 +170,16 @@
...
@@ -149,12 +170,16 @@
jio
.
post
({
"
name
"
:
"
test_name
"
})
jio
.
post
({
"
name
"
:
"
test_name
"
})
.
then
(
function
(
result
)
{
.
then
(
function
(
result
)
{
equal
(
result
,
"
posted
"
);
equal
(
result
,
"
posted
"
);
equal
(
jio
.
__storage
.
_sub_storage_index
.
has
(
"
posted
"
),
true
);
jio
.
__storage
.
_signature_storage
.
get
(
"
posted
"
)
.
then
(
function
(
result
)
{
equal
(
result
.
id
,
"
posted
"
);
});
})
})
.
fail
(
function
(
error
)
{
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
ok
(
false
,
error
);
})
})
.
always
(
function
()
{
.
always
(
function
()
{
indexedDB
.
deleteDatabase
(
'
jio:
'
+
test_signature_database
);
start
();
start
();
});
});
});
});
...
@@ -169,6 +194,10 @@
...
@@ -169,6 +194,10 @@
var
jio
=
jIO
.
createJIO
({
var
jio
=
jIO
.
createJIO
({
type
:
"
list
"
,
type
:
"
list
"
,
signature_storage
:
{
type
:
"
indexeddb
"
,
database
:
test_signature_database
},
sub_storage
:
{
sub_storage
:
{
type
:
"
dummystorage1
"
type
:
"
dummystorage1
"
}
}
...
@@ -182,12 +211,16 @@
...
@@ -182,12 +211,16 @@
jio
.
put
(
"
1
"
,
{
"
name
"
:
"
test_name
"
})
jio
.
put
(
"
1
"
,
{
"
name
"
:
"
test_name
"
})
.
then
(
function
(
result
)
{
.
then
(
function
(
result
)
{
equal
(
result
,
"
1
"
);
equal
(
result
,
"
1
"
);
equal
(
jio
.
__storage
.
_sub_storage_index
.
has
(
"
1
"
),
true
);
jio
.
__storage
.
_signature_storage
.
get
(
"
1
"
)
.
then
(
function
(
result
)
{
equal
(
result
.
id
,
"
1
"
);
});
})
})
.
fail
(
function
(
error
)
{
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
ok
(
false
,
error
);
})
})
.
always
(
function
()
{
.
always
(
function
()
{
indexedDB
.
deleteDatabase
(
'
jio:
'
+
test_signature_database
);
start
();
start
();
});
});
});
});
...
@@ -198,10 +231,14 @@
...
@@ -198,10 +231,14 @@
module
(
"
ListStorage.remove
"
);
module
(
"
ListStorage.remove
"
);
test
(
"
remove called substorage remove
"
,
function
()
{
test
(
"
remove called substorage remove
"
,
function
()
{
stop
();
stop
();
expect
(
5
);
expect
(
4
);
var
jio
=
jIO
.
createJIO
({
var
jio
=
jIO
.
createJIO
({
type
:
"
list
"
,
type
:
"
list
"
,
signature_storage
:
{
type
:
"
indexeddb
"
,
database
:
test_signature_database
},
sub_storage
:
{
sub_storage
:
{
type
:
"
dummystorage1
"
type
:
"
dummystorage1
"
}
}
...
@@ -217,16 +254,19 @@
...
@@ -217,16 +254,19 @@
jio
.
put
(
"
1
"
,
{
"
name
"
:
"
test_name
"
})
jio
.
put
(
"
1
"
,
{
"
name
"
:
"
test_name
"
})
.
then
(
function
(
result
)
{
.
then
(
function
(
result
)
{
equal
(
result
,
"
1
"
);
equal
(
result
,
"
1
"
);
equal
(
jio
.
__storage
.
_sub_storage_index
.
has
(
"
1
"
),
true
);
jio
.
remove
(
"
1
"
)
jio
.
remove
(
"
1
"
)
.
then
(
function
(
result
)
{
.
then
(
function
(
result
)
{
equal
(
result
,
"
1
"
);
equal
(
result
,
"
1
"
);
equal
(
jio
.
__storage
.
_sub_storage_index
.
has
(
"
1
"
),
false
);
jio
.
__storage
.
_signature_storage
.
get
(
"
1
"
)
.
fail
(
function
(
error
)
{
equal
(
error
.
status_code
,
404
);
});
})
})
.
fail
(
function
(
error
)
{
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
ok
(
false
,
error
);
})
})
.
always
(
function
()
{
.
always
(
function
()
{
indexedDB
.
deleteDatabase
(
'
jio:
'
+
test_signature_database
);
start
();
start
();
});
});
});
});
...
@@ -242,6 +282,10 @@
...
@@ -242,6 +282,10 @@
var
jio
=
jIO
.
createJIO
({
var
jio
=
jIO
.
createJIO
({
type
:
"
list
"
,
type
:
"
list
"
,
signature_storage
:
{
type
:
"
indexeddb
"
,
database
:
test_signature_database
},
sub_storage
:
{
sub_storage
:
{
type
:
"
dummystorage1
"
type
:
"
dummystorage1
"
}
}
...
@@ -262,6 +306,7 @@
...
@@ -262,6 +306,7 @@
ok
(
false
,
error
);
ok
(
false
,
error
);
})
})
.
always
(
function
()
{
.
always
(
function
()
{
indexedDB
.
deleteDatabase
(
'
jio:
'
+
test_signature_database
);
start
();
start
();
});
});
});
});
...
@@ -276,6 +321,10 @@
...
@@ -276,6 +321,10 @@
var
jio
=
jIO
.
createJIO
({
var
jio
=
jIO
.
createJIO
({
type
:
"
list
"
,
type
:
"
list
"
,
signature_storage
:
{
type
:
"
indexeddb
"
,
database
:
test_signature_database
},
sub_storage
:
{
sub_storage
:
{
type
:
"
dummystorage1
"
type
:
"
dummystorage1
"
}
}
...
@@ -297,6 +346,7 @@
...
@@ -297,6 +346,7 @@
ok
(
false
,
error
);
ok
(
false
,
error
);
})
})
.
always
(
function
()
{
.
always
(
function
()
{
indexedDB
.
deleteDatabase
(
'
jio:
'
+
test_signature_database
);
start
();
start
();
});
});
});
});
...
@@ -311,6 +361,10 @@
...
@@ -311,6 +361,10 @@
var
jio
=
jIO
.
createJIO
({
var
jio
=
jIO
.
createJIO
({
type
:
"
list
"
,
type
:
"
list
"
,
signature_storage
:
{
type
:
"
indexeddb
"
,
database
:
test_signature_database
},
sub_storage
:
{
sub_storage
:
{
type
:
"
dummystorage1
"
type
:
"
dummystorage1
"
}
}
...
@@ -330,6 +384,7 @@
...
@@ -330,6 +384,7 @@
ok
(
false
,
error
);
ok
(
false
,
error
);
})
})
.
always
(
function
()
{
.
always
(
function
()
{
indexedDB
.
deleteDatabase
(
'
jio:
'
+
test_signature_database
);
start
();
start
();
});
});
});
});
...
@@ -342,6 +397,10 @@
...
@@ -342,6 +397,10 @@
var
jio
=
jIO
.
createJIO
({
var
jio
=
jIO
.
createJIO
({
type
:
"
list
"
,
type
:
"
list
"
,
signature_storage
:
{
type
:
"
indexeddb
"
,
database
:
test_signature_database
},
sub_storage
:
{
sub_storage
:
{
type
:
"
dummystorage1
"
type
:
"
dummystorage1
"
}
}
...
@@ -352,6 +411,8 @@
...
@@ -352,6 +411,8 @@
};
};
ok
(
jio
.
hasCapacity
(
"
list
"
));
ok
(
jio
.
hasCapacity
(
"
list
"
));
indexedDB
.
deleteDatabase
(
'
jio:
'
+
test_signature_database
);
});
});
}(
jIO
,
QUnit
));
}(
jIO
,
QUnit
));
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment