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
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
Douglas
jio
Commits
d195ff81
Commit
d195ff81
authored
Sep 21, 2014
by
Xiaowu Zhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove range storage
parent
419f0dde
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
0 additions
and
1129 deletions
+0
-1129
src/jio.storage/rangestorage.js
src/jio.storage/rangestorage.js
+0
-264
test/jio.storage/rangestorage.tests.js
test/jio.storage/rangestorage.tests.js
+0
-865
No files found.
src/jio.storage/rangestorage.js
deleted
100644 → 0
View file @
419f0dde
/*jslint indent: 2, maxlen: 80, nomen: true, regexp: true, unparam: true */
/*global define, RSVP, jIO */
(
function
(
dependencies
,
module
)
{
"
use strict
"
;
if
(
typeof
define
===
'
function
'
&&
define
.
amd
)
{
return
define
(
dependencies
,
module
);
}
module
(
RSVP
,
jIO
);
}([
'
rsvp
'
,
'
jio
'
],
function
(
RSVP
,
jIO
)
{
"
use strict
"
;
/**
* The jIO QueryStorage extension
*
* @class QueryStorage
* @constructor
*/
function
RangeStorage
(
spec
)
{
if
(
spec
.
sub_storage
===
undefined
)
{
throw
new
TypeError
(
"
RangeStorage 'sub storage' description
"
+
"
must be a non-empty string
"
);
}
if
(
spec
.
sub_storage
.
type
===
"
indexeddb
"
||
spec
.
sub_storage
.
type
===
"
dav
"
)
{
throw
new
TypeError
(
"
RangeStorage 'sub storage'
"
+
spec
.
sub_storage
.
type
+
"
unsupport
"
);
}
this
.
_sub_storage
=
spec
.
sub_storage
;
this
.
_key_schema
=
spec
.
key_schema
;
}
/**
* Get a document
* Parameters are passed through to the sub storage.
*
* @method get
* @param {Object} command The JIO command
*/
RangeStorage
.
prototype
.
get
=
function
(
command
)
{
var
args
=
[].
slice
.
call
(
arguments
,
1
),
substorage
;
substorage
=
command
.
storage
(
this
.
_sub_storage
);
substorage
.
get
.
apply
(
substorage
,
args
).
then
(
command
.
success
,
command
.
error
,
command
.
notify
);
};
/**
* Create a document in the sub storage.
* Parameters are passed through to the sub storage.
*
* @method post
* @param {Object} command The JIO command
*/
RangeStorage
.
prototype
.
post
=
function
(
command
)
{
var
args
=
[].
slice
.
call
(
arguments
,
1
),
substorage
;
substorage
=
command
.
storage
(
this
.
_sub_storage
);
substorage
.
post
.
apply
(
substorage
,
args
).
then
(
command
.
success
,
command
.
error
,
command
.
notify
);
};
/**
* Create or update a document in the sub storage.
* Parameters are passed through to the sub storage.
*
* @method put
* @param {Object} command The JIO command
*/
RangeStorage
.
prototype
.
put
=
function
(
command
)
{
var
args
=
[].
slice
.
call
(
arguments
,
1
),
substorage
;
substorage
=
command
.
storage
(
this
.
_sub_storage
);
substorage
.
put
.
apply
(
substorage
,
args
).
then
(
command
.
success
,
command
.
error
,
command
.
notify
);
};
/**
* Remove a document.
* Parameters are passed through to the sub storage.
*
* @method remove
* @param {Object} command The JIO command
*/
RangeStorage
.
prototype
.
remove
=
function
(
command
)
{
var
args
=
[].
slice
.
call
(
arguments
,
1
),
substorage
;
substorage
=
command
.
storage
(
this
.
_sub_storage
);
substorage
.
remove
.
apply
(
substorage
,
args
).
then
(
command
.
success
,
command
.
error
,
command
.
notify
);
};
/**
* Get an attachment.
* Parameters are passed through to the sub storage.
*
* @method getAttachment
* @param {Object} command The JIO command
*/
RangeStorage
.
prototype
.
getAttachment
=
function
(
command
,
param
)
{
var
args
=
[].
slice
.
call
(
arguments
,
1
),
substorage
;
substorage
=
command
.
storage
(
this
.
_sub_storage
);
substorage
.
getAttachment
.
apply
(
substorage
,
args
).
then
(
function
(
result
)
{
param
.
_start
=
param
.
_start
===
undefined
?
0
:
param
.
_start
;
param
.
_end
=
param
.
_end
===
undefined
?
result
.
data
.
size
:
param
.
_end
;
if
(
param
.
_start
<
0
||
param
.
_end
<
0
)
{
throw
({
"
status
"
:
404
,
"
reason
"
:
"
invalide _start, _end
"
,
"
message
"
:
"
_start and _end must be positive
"
});
}
if
(
param
.
_start
>
param
.
_end
)
{
throw
({
"
status
"
:
404
,
"
reason
"
:
"
invalide offset
"
,
"
message
"
:
"
start is great then end
"
});
}
result
.
data
=
result
.
data
.
slice
(
param
.
_start
,
param
.
_end
);
return
result
;
}).
then
(
command
.
success
,
command
.
error
,
command
.
notify
);
};
/**
* Add an attachment to a document.
* Parameters are passed through to the sub storage.
*
* @method putAttachment
* @param {Object} command The JIO command
*/
RangeStorage
.
prototype
.
putAttachment
=
function
(
command
)
{
var
args
=
[].
slice
.
call
(
arguments
,
1
),
substorage
;
substorage
=
command
.
storage
(
this
.
_sub_storage
);
substorage
.
putAttachment
.
apply
(
substorage
,
args
).
then
(
command
.
success
,
command
.
error
,
command
.
notify
);
};
/**
* Remove an attachment.
* Parameters are passed through to the sub storage.
*
* @method removeAttachment
* @param {Object} command The JIO command
*/
RangeStorage
.
prototype
.
removeAttachment
=
function
(
command
)
{
var
args
=
[].
slice
.
call
(
arguments
,
1
),
substorage
;
substorage
=
command
.
storage
(
this
.
_sub_storage
);
substorage
.
removeAttachment
.
apply
(
substorage
,
args
).
then
(
command
.
success
,
command
.
error
,
command
.
notify
);
};
/**
* Retrieve documents.
* This method performs an .allDocs() call on the substorage,
* retrieving everything, then runs a query on the result.
*
* @method allDocs
* @param {Object} command The given parameters
* @param {Object} options The command options
*/
RangeStorage
.
prototype
.
allDocs
=
function
(
command
,
param
,
options
)
{
var
that
=
this
,
substorage
=
command
.
storage
(
this
.
_sub_storage
),
// we need the full documents in order to perform the query, will
// remove them later if they were not required.
include_docs
=
(
options
.
include_docs
||
options
.
query
)
?
true
:
false
;
substorage
.
allDocs
({
"
include_docs
"
:
include_docs
}).
then
(
function
(
response
)
{
var
data_rows
=
response
.
data
.
rows
,
docs
=
{},
row
,
i
,
l
;
if
(
!
include_docs
)
{
return
response
;
}
if
(
options
.
include_docs
)
{
for
(
i
=
0
,
l
=
data_rows
.
length
;
i
<
l
;
i
+=
1
)
{
row
=
data_rows
[
i
];
docs
[
row
.
id
]
=
JSON
.
parse
(
JSON
.
stringify
(
row
.
doc
));
row
.
doc
.
_id
=
row
.
id
;
data_rows
[
i
]
=
row
.
doc
;
}
}
else
{
for
(
i
=
0
,
l
=
data_rows
.
length
;
i
<
l
;
i
+=
1
)
{
row
=
data_rows
[
i
];
row
.
doc
.
_id
=
row
.
id
;
data_rows
[
i
]
=
row
.
doc
;
}
}
if
(
options
.
select_list
)
{
options
.
select_list
.
push
(
"
_id
"
);
}
return
jIO
.
QueryFactory
.
create
(
options
.
query
||
""
,
that
.
_key_schema
).
exec
(
data_rows
,
options
).
then
(
function
(
filtered_docs
)
{
// reconstruct filtered rows, preserving the order from docs
if
(
options
.
include_docs
)
{
for
(
i
=
0
,
l
=
filtered_docs
.
length
;
i
<
l
;
i
+=
1
)
{
filtered_docs
[
i
]
=
{
"
id
"
:
filtered_docs
[
i
].
_id
,
"
doc
"
:
docs
[
filtered_docs
[
i
].
_id
],
"
value
"
:
options
.
select_list
?
filtered_docs
[
i
]
:
{}
};
delete
filtered_docs
[
i
].
value
.
_id
;
}
}
else
{
for
(
i
=
0
,
l
=
filtered_docs
.
length
;
i
<
l
;
i
+=
1
)
{
filtered_docs
[
i
]
=
{
"
id
"
:
filtered_docs
[
i
].
_id
,
"
value
"
:
options
.
select_list
?
filtered_docs
[
i
]
:
{}
};
delete
filtered_docs
[
i
].
value
.
_id
;
}
}
response
.
data
.
rows
=
filtered_docs
;
response
.
data
.
total_rows
=
filtered_docs
.
length
;
return
response
;
});
}).
then
(
command
.
success
,
command
.
error
,
command
.
notify
);
};
/**
* Check a document
* Parameters are passed through to the sub storage.
*
* @method check
* @param {Object} command The JIO command
*/
RangeStorage
.
prototype
.
check
=
function
(
command
)
{
var
args
=
[].
slice
.
call
(
arguments
,
1
),
substorage
;
substorage
=
command
.
storage
(
this
.
_sub_storage
);
substorage
.
check
.
apply
(
substorage
,
args
).
then
(
command
.
success
,
command
.
error
,
command
.
notify
);
};
/**
* Repair a document
* Parameters are passed through to the sub storage.
*
* @method repair
* @param {Object} command The JIO command
*/
RangeStorage
.
prototype
.
repair
=
function
(
command
)
{
var
args
=
[].
slice
.
call
(
arguments
,
1
),
substorage
;
substorage
=
command
.
storage
(
this
.
_sub_storage
);
substorage
.
repair
.
apply
(
substorage
,
args
).
then
(
command
.
success
,
command
.
error
,
command
.
notify
);
};
jIO
.
addStorage
(
'
range
'
,
RangeStorage
);
}));
test/jio.storage/rangestorage.tests.js
deleted
100644 → 0
View file @
419f0dde
/*jslint indent: 2, maxlen: 80, nomen: true */
/*global window, define, module, test_util, RSVP, jIO, local_storage, test, ok,
deepEqual, sinon, expect, stop, start, Blob, query_storage */
// define([module_name], [dependencies], module);
(
function
(
dependencies
,
module
)
{
"
use strict
"
;
if
(
typeof
define
===
'
function
'
&&
define
.
amd
)
{
return
define
(
dependencies
,
module
);
}
module
(
test_util
,
RSVP
,
jIO
,
local_storage
);
}([
'
test_util
'
,
'
rsvp
'
,
'
jio
'
,
'
localstorage
'
,
'
qunit
'
,
'
rangestorage
'
],
function
(
test_util
,
RSVP
,
jIO
,
local_storage
)
{
"
use strict
"
;
module
(
"
RangeStorage
"
);
function
createQueryStorage
(
name
,
key_schema
)
{
var
local_description
=
local_storage
.
createDescription
(
name
,
name
,
'
memory
'
);
return
jIO
.
createJIO
({
type
:
'
range
'
,
sub_storage
:
local_description
,
key_schema
:
key_schema
},
{
workspace
:
{}
});
}
/*
* What follows is almost a replica of the local storage tests,
* plus a couple of schema queries.
* This is redundant, but guarantees that the storage is working
* under all circumstances.
*/
function
success
(
promise
)
{
return
new
RSVP
.
Promise
(
function
(
resolve
,
reject
,
notify
)
{
/*jslint unparam: true*/
promise
.
then
(
resolve
,
resolve
,
notify
);
},
function
()
{
promise
.
cancel
();
});
}
function
unexpectedError
(
error
)
{
if
(
error
instanceof
Error
)
{
deepEqual
([
error
.
name
+
"
:
"
+
error
.
message
,
error
],
"
UNEXPECTED ERROR
"
,
"
Unexpected error
"
);
}
else
{
deepEqual
(
error
,
"
UNEXPECTED ERROR
"
,
"
Unexpected error
"
);
}
}
test
(
"
post & get
"
,
6
,
function
()
{
var
jio
=
createQueryStorage
(
'
post-get
'
);
stop
();
function
getMissingDocument
()
{
return
success
(
jio
.
get
({
_id
:
'
inexistent
'
}));
}
function
getMissingDocumentTest
(
answer
)
{
deepEqual
(
answer
,
{
"
error
"
:
"
not_found
"
,
"
id
"
:
"
inexistent
"
,
"
message
"
:
"
Cannot find document
"
,
"
method
"
:
"
get
"
,
"
reason
"
:
"
missing
"
,
"
result
"
:
"
error
"
,
"
status
"
:
404
,
"
statusText
"
:
"
Not Found
"
},
"
Get inexistent document
"
);
}
function
postWithoutID
()
{
return
jio
.
post
({});
}
function
postWithoutIDTest
(
answer
)
{
var
uuid
=
answer
.
id
;
delete
answer
.
id
;
deepEqual
(
answer
,
{
"
method
"
:
"
post
"
,
"
result
"
:
"
success
"
,
"
status
"
:
201
,
"
statusText
"
:
"
Created
"
});
ok
(
test_util
.
isUuid
(
uuid
),
"
Uuid should look like
"
+
"
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx :
"
+
uuid
);
}
function
postNonEmptyDocument
()
{
return
jio
.
post
({
"
_id
"
:
"
post1
"
,
"
title
"
:
"
myPost1
"
});
}
function
postNonEmptyDocumentTest
(
answer
)
{
deepEqual
(
answer
,
{
"
id
"
:
"
post1
"
,
"
method
"
:
"
post
"
,
"
result
"
:
"
success
"
,
"
status
"
:
201
,
"
statusText
"
:
"
Created
"
});
}
function
getNonEmptyDocument
()
{
return
jio
.
get
({
"
_id
"
:
"
post1
"
});
}
function
getNonEmptyDocumentTest
(
answer
)
{
deepEqual
(
answer
,
{
"
data
"
:
{
"
_id
"
:
"
post1
"
,
"
title
"
:
"
myPost1
"
},
"
id
"
:
"
post1
"
,
"
method
"
:
"
get
"
,
"
result
"
:
"
success
"
,
"
status
"
:
200
,
"
statusText
"
:
"
Ok
"
});
}
function
postExistingDocument
()
{
return
success
(
jio
.
post
({
"
_id
"
:
"
post1
"
,
"
title
"
:
"
myPost2
"
}));
}
function
postExistingDocumentTest
(
answer
)
{
deepEqual
(
answer
,
{
"
error
"
:
"
conflict
"
,
"
id
"
:
"
post1
"
,
"
message
"
:
"
Cannot create a new document
"
,
"
method
"
:
"
post
"
,
"
reason
"
:
"
document exists
"
,
"
result
"
:
"
error
"
,
"
status
"
:
409
,
"
statusText
"
:
"
Conflict
"
});
}
getMissingDocument
().
then
(
getMissingDocumentTest
).
then
(
postWithoutID
).
then
(
postWithoutIDTest
).
then
(
postNonEmptyDocument
).
then
(
postNonEmptyDocumentTest
).
then
(
getNonEmptyDocument
).
then
(
getNonEmptyDocumentTest
).
then
(
postExistingDocument
).
then
(
postExistingDocumentTest
).
fail
(
unexpectedError
).
always
(
start
);
});
test
(
"
put & get
"
,
4
,
function
()
{
var
jio
=
createQueryStorage
(
'
put-get
'
);
stop
();
function
putNonEmptyDocument
()
{
return
jio
.
put
({
"
_id
"
:
"
put1
"
,
"
title
"
:
"
myPut1
"
});
}
function
putNonEmptyDocumentTest
(
answer
)
{
deepEqual
(
answer
,
{
"
id
"
:
"
put1
"
,
"
method
"
:
"
put
"
,
"
result
"
:
"
success
"
,
"
status
"
:
201
,
"
statusText
"
:
"
Created
"
});
}
function
getNonEmptyDocument
()
{
return
jio
.
get
({
"
_id
"
:
"
put1
"
});
}
function
getNonEmptyDocumentTest
(
answer
)
{
deepEqual
(
answer
,
{
"
data
"
:
{
"
_id
"
:
"
put1
"
,
"
title
"
:
"
myPut1
"
},
"
id
"
:
"
put1
"
,
"
method
"
:
"
get
"
,
"
result
"
:
"
success
"
,
"
status
"
:
200
,
"
statusText
"
:
"
Ok
"
});
}
function
putExistingDocument
()
{
return
success
(
jio
.
put
({
"
_id
"
:
"
put1
"
,
"
title
"
:
"
myPut2
"
}));
}
function
putExistingDocumentTest
(
answer
)
{
deepEqual
(
answer
,
{
"
id
"
:
"
put1
"
,
"
method
"
:
"
put
"
,
"
result
"
:
"
success
"
,
"
status
"
:
204
,
"
statusText
"
:
"
No Content
"
});
}
function
getNonEmptyDocument2
()
{
return
jio
.
get
({
"
_id
"
:
"
put1
"
});
}
function
getNonEmptyDocument2Test
(
answer
)
{
deepEqual
(
answer
,
{
"
data
"
:
{
"
_id
"
:
"
put1
"
,
"
title
"
:
"
myPut2
"
},
"
id
"
:
"
put1
"
,
"
method
"
:
"
get
"
,
"
result
"
:
"
success
"
,
"
status
"
:
200
,
"
statusText
"
:
"
Ok
"
});
}
putNonEmptyDocument
().
then
(
putNonEmptyDocumentTest
).
then
(
getNonEmptyDocument
).
then
(
getNonEmptyDocumentTest
).
then
(
putExistingDocument
).
then
(
putExistingDocumentTest
).
then
(
getNonEmptyDocument2
).
then
(
getNonEmptyDocument2Test
).
fail
(
unexpectedError
).
always
(
start
);
});
test
(
"
putAttachment & get & getAttachment
"
,
22
,
function
()
{
var
jio
=
createQueryStorage
(
'
putattachment-get-getattachment
'
);
stop
();
function
getAttachmentMissingDocument
()
{
return
success
(
jio
.
getAttachment
({
"
_id
"
:
"
inexistent
"
,
"
_attachment
"
:
"
a
"
}));
}
function
getAttachmentMissingDocumentTest
(
answer
)
{
deepEqual
(
answer
,
{
"
attachment
"
:
"
a
"
,
"
error
"
:
"
not_found
"
,
"
id
"
:
"
inexistent
"
,
"
message
"
:
"
Cannot find document
"
,
"
method
"
:
"
getAttachment
"
,
"
reason
"
:
"
missing document
"
,
"
result
"
:
"
error
"
,
"
status
"
:
404
,
"
statusText
"
:
"
Not Found
"
});
}
function
getAttachmentFromEmptyDocument
()
{
var
promise
=
jio
.
put
({
"
_id
"
:
"
b
"
}).
then
(
function
()
{
return
jio
.
getAttachment
({
"
_id
"
:
"
b
"
,
"
_attachment
"
:
"
inexistent
"
});
});
return
success
(
promise
);
}
function
getAttachmentFromEmptyDocumentTest
(
answer
)
{
deepEqual
(
answer
,
{
"
attachment
"
:
"
inexistent
"
,
"
error
"
:
"
not_found
"
,
"
id
"
:
"
b
"
,
"
message
"
:
"
Cannot find attachment
"
,
"
method
"
:
"
getAttachment
"
,
"
reason
"
:
"
missing attachment
"
,
"
result
"
:
"
error
"
,
"
status
"
:
404
,
"
statusText
"
:
"
Not Found
"
});
}
function
putAttachmentMissingDocument
()
{
return
success
(
jio
.
putAttachment
({
"
_id
"
:
"
inexistent
"
,
"
_attachment
"
:
"
putattmt2
"
,
"
_data
"
:
""
}));
}
function
putAttachmentMissingDocumentTest
(
answer
)
{
deepEqual
(
answer
,
{
"
attachment
"
:
"
putattmt2
"
,
"
error
"
:
"
not_found
"
,
"
id
"
:
"
inexistent
"
,
"
message
"
:
"
Impossible to add attachment
"
,
"
method
"
:
"
putAttachment
"
,
"
reason
"
:
"
missing
"
,
"
result
"
:
"
error
"
,
"
status
"
:
404
,
"
statusText
"
:
"
Not Found
"
});
}
function
addAttachment
()
{
var
promise
=
jio
.
put
({
"
_id
"
:
"
putattmt1
"
,
"
title
"
:
"
myPutAttmt1
"
}).
then
(
function
()
{
return
jio
.
putAttachment
({
"
_id
"
:
"
putattmt1
"
,
"
_attachment
"
:
"
putattmt2
"
,
"
_data
"
:
"
itisatest
"
});
});
return
success
(
promise
);
}
function
addAttachmentTest
(
answer
)
{
deepEqual
(
answer
,
{
"
attachment
"
:
"
putattmt2
"
,
"
digest
"
:
"
sha256-85c53b5ddf71938360f5452b77d0
"
+
"
176e3013e347cb1766c2f67bb783f31b4278
"
,
"
id
"
:
"
putattmt1
"
,
"
method
"
:
"
putAttachment
"
,
"
result
"
:
"
success
"
,
"
status
"
:
201
,
"
statusText
"
:
"
Created
"
});
}
function
checkDocumentAndAttachment
()
{
return
RSVP
.
all
([
jio
.
get
({
"
_id
"
:
"
putattmt1
"
}),
jio
.
getAttachment
({
"
_id
"
:
"
putattmt1
"
,
"
_attachment
"
:
"
putattmt2
"
})
]);
}
function
checkDocumentAndAttachmentTest
(
answers
)
{
var
blob
;
deepEqual
(
answers
[
0
],
{
"
data
"
:
{
"
_attachments
"
:
{
"
putattmt2
"
:
{
"
content_type
"
:
""
,
"
digest
"
:
"
sha256-85c53b5ddf71938360f5452b77d0
"
+
"
176e3013e347cb1766c2f67bb783f31b4278
"
,
"
length
"
:
9
}
},
"
_id
"
:
"
putattmt1
"
,
"
title
"
:
"
myPutAttmt1
"
},
"
id
"
:
"
putattmt1
"
,
"
method
"
:
"
get
"
,
"
result
"
:
"
success
"
,
"
status
"
:
200
,
"
statusText
"
:
"
Ok
"
});
ok
(
answers
[
1
].
data
instanceof
Blob
,
"
Data is Blob
"
);
deepEqual
(
answers
[
1
].
data
.
type
,
""
,
"
Check mimetype
"
);
deepEqual
(
answers
[
1
].
data
.
size
,
9
,
"
Check size
"
);
blob
=
answers
[
1
].
data
;
delete
answers
[
1
].
data
;
deepEqual
(
answers
[
1
],
{
"
attachment
"
:
"
putattmt2
"
,
"
id
"
:
"
putattmt1
"
,
"
digest
"
:
"
sha256-85c53b5ddf71938360f5452b77d0
"
+
"
176e3013e347cb1766c2f67bb783f31b4278
"
,
"
method
"
:
"
getAttachment
"
,
"
result
"
:
"
success
"
,
"
status
"
:
200
,
"
statusText
"
:
"
Ok
"
},
"
Get Attachment, Check Response
"
);
return
jIO
.
util
.
readBlobAsText
(
blob
).
then
(
function
(
e
)
{
deepEqual
(
e
.
target
.
result
,
"
itisatest
"
,
"
Check blob text content
"
);
});
}
function
getAttachmentRange1
()
{
return
jio
.
getAttachment
({
"
_id
"
:
"
putattmt1
"
,
"
_attachment
"
:
"
putattmt2
"
,
"
_start
"
:
2
,
"
_end
"
:
4
});
}
function
getAttachmentRangeTest1
(
answers
)
{
var
blob
;
ok
(
answers
.
data
instanceof
Blob
,
"
Data is Blob
"
);
deepEqual
(
answers
.
data
.
type
,
""
,
"
Check mimetype
"
);
deepEqual
(
answers
.
data
.
size
,
2
,
"
Check size
"
);
blob
=
answers
.
data
;
delete
answers
.
data
;
deepEqual
(
answers
,
{
"
attachment
"
:
"
putattmt2
"
,
"
id
"
:
"
putattmt1
"
,
"
digest
"
:
"
sha256-85c53b5ddf71938360f5452b77d0
"
+
"
176e3013e347cb1766c2f67bb783f31b4278
"
,
"
method
"
:
"
getAttachment
"
,
"
result
"
:
"
success
"
,
"
status
"
:
200
,
"
statusText
"
:
"
Ok
"
},
"
Get Attachment with _start:2 _end: 4, Check Response
"
);
return
jIO
.
util
.
readBlobAsText
(
blob
).
then
(
function
(
e
)
{
deepEqual
(
e
.
target
.
result
,
"
is
"
,
"
Check blob text content
"
);
});
}
function
getAttachmentRange2
()
{
return
jio
.
getAttachment
({
"
_id
"
:
"
putattmt1
"
,
"
_attachment
"
:
"
putattmt2
"
,
"
_start
"
:
1
,
"
_end
"
:
7
});
}
function
getAttachmentRangeTest2
(
answers
)
{
var
blob
;
ok
(
answers
.
data
instanceof
Blob
,
"
Data is Blob
"
);
deepEqual
(
answers
.
data
.
type
,
""
,
"
Check mimetype
"
);
deepEqual
(
answers
.
data
.
size
,
6
,
"
Check size
"
);
blob
=
answers
.
data
;
delete
answers
.
data
;
deepEqual
(
answers
,
{
"
attachment
"
:
"
putattmt2
"
,
"
id
"
:
"
putattmt1
"
,
"
digest
"
:
"
sha256-85c53b5ddf71938360f5452b77d0
"
+
"
176e3013e347cb1766c2f67bb783f31b4278
"
,
"
method
"
:
"
getAttachment
"
,
"
result
"
:
"
success
"
,
"
status
"
:
200
,
"
statusText
"
:
"
Ok
"
},
"
Get Attachment with _start: 1 _end: 7, Check Response
"
);
return
jIO
.
util
.
readBlobAsText
(
blob
).
then
(
function
(
e
)
{
deepEqual
(
e
.
target
.
result
,
"
tisate
"
,
"
Check blob text content
"
);
});
}
function
getAttachmentRange3
()
{
return
success
(
jio
.
getAttachment
({
"
_id
"
:
"
putattmt1
"
,
"
_attachment
"
:
"
putattmt2
"
,
"
_start
"
:
-
2
,
"
_end
"
:
4
}));
}
function
getAttachmentRangeTest3
(
answer
)
{
deepEqual
(
answer
,
{
"
attachment
"
:
"
putattmt2
"
,
"
error
"
:
"
not_found
"
,
"
id
"
:
"
putattmt1
"
,
"
message
"
:
"
_start and _end must be positive
"
,
"
method
"
:
"
getAttachment
"
,
"
reason
"
:
"
invalide _start, _end
"
,
"
result
"
:
"
error
"
,
"
status
"
:
404
,
"
statusText
"
:
"
Not Found
"
},
"
get attachment with _start or _end negative -> 404 Not Found
"
);
}
function
getAttachmentRange4
()
{
return
success
(
jio
.
getAttachment
({
"
_id
"
:
"
putattmt1
"
,
"
_attachment
"
:
"
putattmt2
"
,
"
_start
"
:
6
,
"
_end
"
:
4
}));
}
function
getAttachmentRangeTest4
(
answer
)
{
deepEqual
(
answer
,
{
"
attachment
"
:
"
putattmt2
"
,
"
error
"
:
"
not_found
"
,
"
id
"
:
"
putattmt1
"
,
"
message
"
:
"
start is great then end
"
,
"
method
"
:
"
getAttachment
"
,
"
reason
"
:
"
invalide offset
"
,
"
result
"
:
"
error
"
,
"
status
"
:
404
,
"
statusText
"
:
"
Not Found
"
},
"
get attachment with _start < _end -> 404 Not Found
"
);
}
getAttachmentMissingDocument
().
then
(
getAttachmentMissingDocumentTest
).
then
(
getAttachmentFromEmptyDocument
).
then
(
getAttachmentFromEmptyDocumentTest
).
then
(
putAttachmentMissingDocument
).
then
(
putAttachmentMissingDocumentTest
).
then
(
addAttachment
).
then
(
addAttachmentTest
).
then
(
checkDocumentAndAttachment
).
then
(
checkDocumentAndAttachmentTest
).
then
(
getAttachmentRange1
).
then
(
getAttachmentRangeTest1
).
then
(
getAttachmentRange2
).
then
(
getAttachmentRangeTest2
).
then
(
getAttachmentRange3
).
then
(
getAttachmentRangeTest3
).
then
(
getAttachmentRange4
).
then
(
getAttachmentRangeTest4
).
fail
(
unexpectedError
).
always
(
start
);
});
test
(
"
remove & removeAttachment
"
,
5
,
function
()
{
var
jio
=
createQueryStorage
(
'
remove-removeattachment
'
);
stop
();
function
putAttachment
()
{
var
promise
=
jio
.
put
({
"
_id
"
:
"
a
"
}).
then
(
function
()
{
return
jio
.
putAttachment
({
"
_id
"
:
"
a
"
,
"
_attachment
"
:
"
b
"
,
"
_data
"
:
"
c
"
});
});
return
promise
;
}
function
putAttachmentTest
(
answer
)
{
deepEqual
(
answer
,
{
"
attachment
"
:
"
b
"
,
"
digest
"
:
"
sha256-2e7d2c03a9507ae265ecf5b5356885a53
"
+
"
393a2029d241394997265a1a25aefc6
"
,
"
id
"
:
"
a
"
,
"
method
"
:
"
putAttachment
"
,
"
result
"
:
"
success
"
,
"
status
"
:
201
,
"
statusText
"
:
"
Created
"
});
}
function
removeAttachment
()
{
return
success
(
jio
.
removeAttachment
({
"
_id
"
:
"
a
"
,
"
_attachment
"
:
"
b
"
}));
}
function
removeAttachmentTest
(
answer
)
{
deepEqual
(
answer
,
{
"
attachment
"
:
"
b
"
,
"
id
"
:
"
a
"
,
"
method
"
:
"
removeAttachment
"
,
"
result
"
:
"
success
"
,
"
status
"
:
204
,
"
statusText
"
:
"
No Content
"
});
}
function
removeAttachmentAgainTest
(
answer
)
{
deepEqual
(
answer
,
{
"
attachment
"
:
"
b
"
,
"
error
"
:
"
not_found
"
,
"
id
"
:
"
a
"
,
"
message
"
:
"
Attachment not found
"
,
"
method
"
:
"
removeAttachment
"
,
"
reason
"
:
"
missing attachment
"
,
"
result
"
:
"
error
"
,
"
status
"
:
404
,
"
statusText
"
:
"
Not Found
"
});
}
function
removeDocument
()
{
return
success
(
jio
.
remove
({
"
_id
"
:
"
a
"
}));
}
function
removeDocumentTest
(
answer
)
{
deepEqual
(
answer
,
{
"
id
"
:
"
a
"
,
"
method
"
:
"
remove
"
,
"
result
"
:
"
success
"
,
"
status
"
:
204
,
"
statusText
"
:
"
No Content
"
});
}
function
removeDocumentAgainTest
(
answer
)
{
deepEqual
(
answer
,
{
"
error
"
:
"
not_found
"
,
"
id
"
:
"
a
"
,
"
message
"
:
"
Document not found
"
,
"
method
"
:
"
remove
"
,
"
reason
"
:
"
missing
"
,
"
result
"
:
"
error
"
,
"
status
"
:
404
,
"
statusText
"
:
"
Not Found
"
});
}
putAttachment
().
then
(
putAttachmentTest
).
then
(
removeAttachment
).
then
(
removeAttachmentTest
).
then
(
removeAttachment
).
then
(
removeAttachmentAgainTest
).
then
(
removeDocument
).
then
(
removeDocumentTest
).
then
(
removeDocument
).
then
(
removeDocumentAgainTest
).
fail
(
unexpectedError
).
always
(
start
);
});
test
(
"
allDocs
"
,
5
,
function
()
{
var
jio
=
createQueryStorage
(
'
alldocs
'
),
key_schema
=
{
key_set
:
{
case_insensitive_title
:
{
read_from
:
'
title
'
,
equal_match
:
function
(
object_value
,
value
)
{
return
(
object_value
.
toLowerCase
()
===
value
.
toLowerCase
());
}
}
}
};
stop
();
function
putDocuments
()
{
var
date_a
=
new
Date
(
0
),
date_b
=
new
Date
(
1234567890000
);
return
RSVP
.
all
([
jio
.
put
({
"
_id
"
:
"
a
"
,
"
title
"
:
"
one
"
,
"
date
"
:
date_a
}).
then
(
function
()
{
return
jio
.
putAttachment
({
"
_id
"
:
"
a
"
,
"
_attachment
"
:
"
aa
"
,
"
_data
"
:
"
aaa
"
});
}),
jio
.
put
({
"
_id
"
:
"
b
"
,
"
title
"
:
"
two
"
,
"
date
"
:
date_a
}),
jio
.
put
({
"
_id
"
:
"
c
"
,
"
title
"
:
"
one
"
,
"
date
"
:
date_b
}),
jio
.
put
({
"
_id
"
:
"
d
"
,
"
title
"
:
"
two
"
,
"
date
"
:
date_b
})
]);
}
function
putDocumentsTest
(
answer
)
{
// sort answer rows for comparison
if
(
answer
.
data
&&
answer
.
data
.
rows
)
{
answer
.
data
.
rows
.
sort
(
function
(
a
,
b
)
{
return
a
.
id
<
b
.
id
?
-
1
:
a
.
id
>
b
.
id
?
1
:
0
;
});
}
deepEqual
(
answer
,
[
{
"
attachment
"
:
"
aa
"
,
"
digest
"
:
"
sha256-9834876dcfb05cb167a5c24953eba58
"
+
"
c4ac89b1adf57f28f2f9d09af107ee8f0
"
,
"
id
"
:
"
a
"
,
"
method
"
:
"
putAttachment
"
,
"
result
"
:
"
success
"
,
"
status
"
:
201
,
"
statusText
"
:
"
Created
"
},
{
"
id
"
:
"
b
"
,
"
method
"
:
"
put
"
,
"
result
"
:
"
success
"
,
"
status
"
:
201
,
"
statusText
"
:
"
Created
"
},
{
"
id
"
:
"
c
"
,
"
method
"
:
"
put
"
,
"
result
"
:
"
success
"
,
"
status
"
:
201
,
"
statusText
"
:
"
Created
"
},
{
"
id
"
:
"
d
"
,
"
method
"
:
"
put
"
,
"
result
"
:
"
success
"
,
"
status
"
:
201
,
"
statusText
"
:
"
Created
"
}
]);
}
function
listDocuments
()
{
return
jio
.
allDocs
();
}
function
listDocumentsTest
(
answer
)
{
deepEqual
(
answer
,
{
"
data
"
:
{
"
rows
"
:
[
{
"
id
"
:
"
a
"
,
"
key
"
:
"
a
"
,
"
value
"
:
{}
},
{
"
id
"
:
"
b
"
,
"
key
"
:
"
b
"
,
"
value
"
:
{}
},
{
"
id
"
:
"
c
"
,
"
key
"
:
"
c
"
,
"
value
"
:
{}
},
{
"
id
"
:
"
d
"
,
"
key
"
:
"
d
"
,
"
value
"
:
{}
}
],
"
total_rows
"
:
4
},
"
method
"
:
"
allDocs
"
,
"
result
"
:
"
success
"
,
"
status
"
:
200
,
"
statusText
"
:
"
Ok
"
});
}
function
listDocumentsQuery
()
{
return
jio
.
allDocs
({
"
include_docs
"
:
true
,
"
query
"
:
"
title:
\"
two
\"
"
});
}
function
listDocumentsQueryTest
(
answer
)
{
deepEqual
(
answer
,
{
"
data
"
:
{
"
rows
"
:
[
{
"
doc
"
:
{
"
_id
"
:
"
b
"
,
"
date
"
:
"
1970-01-01T00:00:00.000Z
"
,
"
title
"
:
"
two
"
},
"
id
"
:
"
b
"
,
"
value
"
:
{}
},
{
"
doc
"
:
{
"
_id
"
:
"
d
"
,
"
date
"
:
"
2009-02-13T23:31:30.000Z
"
,
"
title
"
:
"
two
"
},
"
id
"
:
"
d
"
,
"
value
"
:
{}
}
],
"
total_rows
"
:
2
},
"
method
"
:
"
allDocs
"
,
"
result
"
:
"
success
"
,
"
status
"
:
200
,
"
statusText
"
:
"
Ok
"
});
}
function
listDocumentSchemaQueryNoDocs
()
{
var
jio_schema
=
createQueryStorage
(
'
alldocs
'
,
key_schema
);
return
jio_schema
.
allDocs
({
"
include_docs
"
:
false
,
"
query
"
:
"
case_insensitive_title:
\"
oNe
\"
"
});
}
function
listDocumentSchemaQueryNoDocsTest
(
answer
)
{
deepEqual
(
answer
,
{
"
data
"
:
{
"
rows
"
:
[
{
"
id
"
:
"
a
"
,
"
value
"
:
{}
},
{
"
id
"
:
"
c
"
,
"
value
"
:
{}
}
],
"
total_rows
"
:
2
},
"
method
"
:
"
allDocs
"
,
"
result
"
:
"
success
"
,
"
status
"
:
200
,
"
statusText
"
:
"
Ok
"
});
}
function
listDocumentSchemaQueryWithDocs
()
{
var
jio_schema
=
createQueryStorage
(
'
alldocs
'
,
key_schema
);
return
jio_schema
.
allDocs
({
"
include_docs
"
:
true
,
"
query
"
:
"
case_insensitive_title:
\"
oNe
\"
"
});
}
function
listDocumentSchemaQueryWithDocsTest
(
answer
)
{
deepEqual
(
answer
,
{
"
data
"
:
{
"
rows
"
:
[
{
"
doc
"
:
{
"
_attachments
"
:
{
"
aa
"
:
{
"
content_type
"
:
""
,
"
digest
"
:
"
sha256-9834876dcfb05cb167a5c24953eba58c
"
+
"
4ac89b1adf57f28f2f9d09af107ee8f0
"
,
"
length
"
:
3
}
},
"
_id
"
:
"
a
"
,
"
date
"
:
"
1970-01-01T00:00:00.000Z
"
,
"
title
"
:
"
one
"
},
"
id
"
:
"
a
"
,
"
value
"
:
{}
},
{
"
doc
"
:
{
"
_id
"
:
"
c
"
,
"
date
"
:
"
2009-02-13T23:31:30.000Z
"
,
"
title
"
:
"
one
"
},
"
id
"
:
"
c
"
,
"
value
"
:
{}
}
],
"
total_rows
"
:
2
},
"
method
"
:
"
allDocs
"
,
"
result
"
:
"
success
"
,
"
status
"
:
200
,
"
statusText
"
:
"
Ok
"
});
}
putDocuments
().
then
(
putDocumentsTest
).
then
(
listDocuments
).
then
(
listDocumentsTest
).
then
(
listDocumentsQuery
).
then
(
listDocumentsQueryTest
).
then
(
listDocumentSchemaQueryNoDocs
).
then
(
listDocumentSchemaQueryNoDocsTest
).
then
(
listDocumentSchemaQueryWithDocs
).
then
(
listDocumentSchemaQueryWithDocsTest
).
fail
(
unexpectedError
).
always
(
start
);
});
// XXX check/repair not tested yet, may change soon btw
// test("check & repair", 18, function () {
// })
}));
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