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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Romain Courteaud
jio
Commits
9d9506b7
Commit
9d9506b7
authored
Feb 20, 2019
by
preetwinder
Committed by
Romain Courteaud
Apr 19, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use jio storage for ids
parent
a273526b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
131 additions
and
49 deletions
+131
-49
examples/scenario.js
examples/scenario.js
+11
-2
src/jio.storage/liststorage.js
src/jio.storage/liststorage.js
+14
-12
test/jio.storage/liststorage.tests.js
test/jio.storage/liststorage.tests.js
+106
-35
No files found.
examples/scenario.js
View file @
9d9506b7
...
...
@@ -18,7 +18,7 @@
* See https://www.nexedi.com/licensing for rationale and options.
*/
/*global console, btoa, Blob*/
/*global console, btoa, Blob
, indexedDB
*/
/*jslint nomen: true, maxlen: 200*/
(
function
(
window
,
QUnit
,
jIO
,
rJS
)
{
"
use strict
"
;
...
...
@@ -28,7 +28,9 @@
ok
=
QUnit
.
ok
,
stop
=
QUnit
.
stop
,
start
=
QUnit
.
start
,
deepEqual
=
QUnit
.
deepEqual
;
deepEqual
=
QUnit
.
deepEqual
,
test_signature_database
=
'
test_signature_storage_scenario
'
;
rJS
(
window
)
...
...
@@ -61,6 +63,10 @@
type
:
"
query
"
,
sub_storage
:
{
type
:
"
list
"
,
signature_storage
:
{
type
:
"
indexeddb
"
,
database
:
test_signature_database
},
sub_storage
:
{
type
:
"
nocapacity
"
,
sub_storage
:
{
...
...
@@ -368,6 +374,9 @@
.
then
(
function
()
{
return
jio
.
repair
();
})
.
then
(
function
()
{
return
indexedDB
.
deleteDatabase
(
'
jio:
'
+
test_signature_database
);
})
.
fail
(
function
(
error
)
{
console
.
error
(
"
---
"
);
...
...
src/jio.storage/liststorage.js
View file @
9d9506b7
...
...
@@ -24,7 +24,7 @@
function
ListStorage
(
spec
)
{
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
()
{
...
...
@@ -37,24 +37,30 @@
var
gadget
=
this
;
return
gadget
.
_sub_storage
.
post
(
value
)
.
push
(
function
(
id
)
{
gadget
.
_sub_storage_index
.
add
(
id
);
return
id
;
return
gadget
.
_signature_storage
.
put
(
id
,
{
"
id
"
:
id
})
.
push
(
function
()
{
return
id
;
});
});
};
ListStorage
.
prototype
.
put
=
function
(
id
,
value
)
{
var
gadget
=
this
;
return
gadget
.
_sub_storage
.
put
(
id
,
value
)
.
push
(
function
(
result
)
{
gadget
.
_sub_storage_index
.
add
(
id
);
return
result
;
return
gadget
.
_signature_storage
.
put
(
id
,
{
"
id
"
:
id
})
.
push
(
function
()
{
return
result
;
});
});
};
ListStorage
.
prototype
.
remove
=
function
(
id
)
{
var
gadget
=
this
;
return
gadget
.
_sub_storage
.
remove
(
id
)
.
push
(
function
(
result
)
{
gadget
.
_sub_storage_index
.
delete
(
id
);
return
result
;
return
gadget
.
_signature_storage
.
remove
(
id
)
.
push
(
function
()
{
return
result
;
});
});
};
ListStorage
.
prototype
.
getAttachment
=
function
()
{
...
...
@@ -76,11 +82,7 @@
}
};
ListStorage
.
prototype
.
buildQuery
=
function
()
{
var
rows
=
[],
i
,
ids
=
Array
.
from
(
this
.
_sub_storage_index
);
for
(
i
=
0
;
i
<
ids
.
length
;
i
+=
1
)
{
rows
.
push
({
id
:
ids
[
i
],
value
:
{}});
}
return
rows
;
return
this
.
_signature_storage
.
buildQuery
({});
};
jIO
.
addStorage
(
'
list
'
,
ListStorage
);
...
...
test/jio.storage/liststorage.tests.js
View file @
9d9506b7
...
...
@@ -33,15 +33,20 @@
/////////////////////////////////////////////////////////////////
// Custom test substorage definition
/////////////////////////////////////////////////////////////////
function
DummyStorage
()
{
function
DummyStorage
1
()
{
return
this
;
}
jIO
.
addStorage
(
'
dummystorage1
'
,
DummyStorage
);
function
DummyStorage2
()
{
return
this
;
}
jIO
.
addStorage
(
'
dummystorage1
'
,
DummyStorage1
);
jIO
.
addStorage
(
'
dummystorage2
'
,
DummyStorage2
);
/////////////////////////////////////////////////////////////////
// ListStorage constructor
/////////////////////////////////////////////////////////////////
module
(
"
ListStorage.constructor
"
);
test
(
"
create storage
"
,
function
()
{
...
...
@@ -49,11 +54,14 @@
type
:
"
list
"
,
sub_storage
:
{
type
:
"
dummystorage1
"
},
signature_storage
:
{
type
:
"
dummystorage2
"
,
}
});
equal
(
jio
.
__type
,
"
list
"
);
equal
(
jio
.
__storage
.
_sub_storage
.
__type
,
"
dummystorage1
"
);
equal
(
jio
.
__storage
.
_s
ub_storage_index
.
constructor
.
name
,
"
Set
"
);
equal
(
jio
.
__storage
.
_s
ignature_storage
.
__type
,
"
dummystorage2
"
);
});
/////////////////////////////////////////////////////////////////
...
...
@@ -70,19 +78,20 @@
type
:
"
list
"
,
sub_storage
:
{
type
:
"
dummystorage1
"
},
signature_storage
:
{
type
:
"
dummystorage2
"
,
}
});
DummyStorage
.
prototype
.
get
=
function
(
id
)
{
DummyStorage
1
.
prototype
.
get
=
function
(
id
)
{
equal
(
id
,
"
1
"
);
return
{
"
name
"
:
"
test_name
"
};
};
jio
.
get
(
"
1
"
)
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{
"
name
"
:
"
test_name
"
});
deepEqual
(
result
,
{
"
name
"
:
"
test_name
"
});
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
...
...
@@ -104,10 +113,13 @@
type
:
"
list
"
,
sub_storage
:
{
type
:
"
dummystorage1
"
},
signature_storage
:
{
type
:
"
dummystorage2
"
,
}
});
DummyStorage
.
prototype
.
allAttachments
=
function
(
id
)
{
DummyStorage
1
.
prototype
.
allAttachments
=
function
(
id
)
{
equal
(
id
,
"
1
"
);
return
{
attachmentname
:
{}};
};
...
...
@@ -132,24 +144,31 @@
module
(
"
ListStorage.post
"
);
test
(
"
post called substorage post
"
,
function
()
{
stop
();
expect
(
3
);
expect
(
4
);
var
jio
=
jIO
.
createJIO
({
type
:
"
list
"
,
sub_storage
:
{
type
:
"
dummystorage1
"
},
signature_storage
:
{
type
:
"
dummystorage2
"
,
}
});
DummyStorage
.
prototype
.
post
=
function
(
param
)
{
DummyStorage
1
.
prototype
.
post
=
function
(
param
)
{
deepEqual
(
param
,
{
"
name
"
:
"
test_name
"
});
return
"
posted
"
;
};
DummyStorage2
.
prototype
.
put
=
function
(
id
,
value
)
{
equal
(
id
,
'
posted
'
);
deepEqual
(
value
,
{
'
id
'
:
'
posted
'
});
return
id
;
};
jio
.
post
({
"
name
"
:
"
test_name
"
})
.
then
(
function
(
result
)
{
equal
(
result
,
"
posted
"
);
equal
(
jio
.
__storage
.
_sub_storage_index
.
has
(
"
posted
"
),
true
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
...
...
@@ -165,24 +184,31 @@
module
(
"
ListStorage.put
"
);
test
(
"
put called substorage put
"
,
function
()
{
stop
();
expect
(
4
);
expect
(
5
);
var
jio
=
jIO
.
createJIO
({
type
:
"
list
"
,
sub_storage
:
{
type
:
"
dummystorage1
"
},
signature_storage
:
{
type
:
"
dummystorage2
"
,
}
});
DummyStorage
.
prototype
.
put
=
function
(
id
,
param
)
{
DummyStorage
1
.
prototype
.
put
=
function
(
id
,
param
)
{
equal
(
id
,
"
1
"
);
deepEqual
(
param
,
{
"
name
"
:
"
test_name
"
});
return
id
;
};
DummyStorage2
.
prototype
.
put
=
function
(
id
,
param
)
{
equal
(
id
,
"
1
"
);
deepEqual
(
param
,
{
'
id
'
:
'
1
'
});
return
id
;
};
jio
.
put
(
"
1
"
,
{
"
name
"
:
"
test_name
"
})
.
then
(
function
(
result
)
{
equal
(
result
,
"
1
"
);
equal
(
jio
.
__storage
.
_sub_storage_index
.
has
(
"
1
"
),
true
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
...
...
@@ -198,37 +224,35 @@
module
(
"
ListStorage.remove
"
);
test
(
"
remove called substorage remove
"
,
function
()
{
stop
();
expect
(
5
);
expect
(
3
);
var
jio
=
jIO
.
createJIO
({
type
:
"
list
"
,
sub_storage
:
{
type
:
"
dummystorage1
"
},
signature_storage
:
{
type
:
"
dummystorage2
"
,
}
});
DummyStorage
.
prototype
.
remove
=
function
(
id
)
{
deepE
qual
(
id
,
"
1
"
);
DummyStorage
1
.
prototype
.
remove
=
function
(
id
)
{
e
qual
(
id
,
"
1
"
);
return
id
;
};
DummyStorage
.
prototype
.
put
=
function
(
id
)
{
DummyStorage2
.
prototype
.
remove
=
function
(
id
)
{
equal
(
id
,
"
1
"
);
return
id
;
};
jio
.
put
(
"
1
"
,
{
"
name
"
:
"
test_name
"
}
)
jio
.
remove
(
"
1
"
)
.
then
(
function
(
result
)
{
equal
(
result
,
"
1
"
);
equal
(
jio
.
__storage
.
_sub_storage_index
.
has
(
"
1
"
),
true
);
jio
.
remove
(
"
1
"
)
.
then
(
function
(
result
)
{
equal
(
result
,
"
1
"
);
equal
(
jio
.
__storage
.
_sub_storage_index
.
has
(
"
1
"
),
false
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
...
...
@@ -244,11 +268,14 @@
type
:
"
list
"
,
sub_storage
:
{
type
:
"
dummystorage1
"
},
signature_storage
:
{
type
:
"
dummystorage2
"
,
}
}),
blob
=
new
Blob
([
""
]);
DummyStorage
.
prototype
.
getAttachment
=
function
(
id
,
name
)
{
DummyStorage
1
.
prototype
.
getAttachment
=
function
(
id
,
name
)
{
equal
(
id
,
"
1
"
);
equal
(
name
,
"
test_name
"
);
return
blob
;
...
...
@@ -278,11 +305,14 @@
type
:
"
list
"
,
sub_storage
:
{
type
:
"
dummystorage1
"
},
signature_storage
:
{
type
:
"
dummystorage2
"
,
}
}),
blob
=
new
Blob
([
""
]);
DummyStorage
.
prototype
.
putAttachment
=
function
(
id
,
name
,
blob2
)
{
DummyStorage
1
.
prototype
.
putAttachment
=
function
(
id
,
name
,
blob2
)
{
equal
(
id
,
"
1
"
);
equal
(
name
,
"
test_name
"
);
deepEqual
(
blob2
,
blob
);
...
...
@@ -313,10 +343,13 @@
type
:
"
list
"
,
sub_storage
:
{
type
:
"
dummystorage1
"
},
signature_storage
:
{
type
:
"
dummystorage2
"
,
}
});
DummyStorage
.
prototype
.
removeAttachment
=
function
(
id
,
name
)
{
DummyStorage
1
.
prototype
.
removeAttachment
=
function
(
id
,
name
)
{
equal
(
id
,
"
1
"
);
equal
(
name
,
"
test_name
"
);
return
"
removed
"
;
...
...
@@ -344,14 +377,52 @@
type
:
"
list
"
,
sub_storage
:
{
type
:
"
dummystorage1
"
},
signature_storage
:
{
type
:
"
dummystorage2
"
,
}
});
DummyStorage
.
prototype
.
hasCapacity
=
function
()
{
DummyStorage
1
.
prototype
.
hasCapacity
=
function
()
{
return
false
;
};
ok
(
jio
.
hasCapacity
(
"
list
"
));
});
/////////////////////////////////////////////////////////////////
// ListStorage.buildQuery
/////////////////////////////////////////////////////////////////
module
(
"
ListStorage.buildQuery
"
);
test
(
"
buildQuery calls substorage buildQuery
"
,
function
()
{
stop
();
expect
(
2
);
var
jio
=
jIO
.
createJIO
({
type
:
"
list
"
,
sub_storage
:
{
type
:
"
dummystorage1
"
},
signature_storage
:
{
type
:
"
dummystorage2
"
,
}
});
DummyStorage2
.
prototype
.
buildQuery
=
function
(
params
)
{
deepEqual
(
params
,
{});
return
[{
"
id
"
:
"
1
"
},
{
"
id
"
:
"
2
"
}];
};
jio
.
buildQuery
({})
.
then
(
function
(
result
)
{
deepEqual
(
result
,
[{
"
id
"
:
"
1
"
},
{
"
id
"
:
"
2
"
}]);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
}(
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