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
Bryan Kaperick
jio
Commits
5f5edb5f
Commit
5f5edb5f
authored
Jun 12, 2018
by
Bryan Kaperick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Made changes to Gruntfile.js and tests.html to update bryanstorage to historystorage.
parent
7b0cdad4
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
5 additions
and
1039 deletions
+5
-1039
Gruntfile.js
Gruntfile.js
+2
-1
src/jio.storage/bryanstorage.js
src/jio.storage/bryanstorage.js
+0
-311
test/jio.storage/bryanstorage.tests.js
test/jio.storage/bryanstorage.tests.js
+0
-724
test/tests.html
test/tests.html
+3
-3
No files found.
Gruntfile.js
View file @
5f5edb5f
...
...
@@ -183,7 +183,8 @@ module.exports = function (grunt) {
'
src/jio.storage/cryptstorage.js
'
,
'
src/jio.storage/websqlstorage.js
'
,
'
src/jio.storage/fbstorage.js
'
,
'
src/jio.storage/bryanstorage.js
'
'
src/jio.storage/historystorage.js
'
,
'
src/jio.storage/revisionstorage.js
'
],
dest
:
'
dist/<%= pkg.name %>-<%= pkg.version %>.js
'
// dest: 'jio.js'
...
...
src/jio.storage/bryanstorage.js
deleted
100644 → 0
View file @
7b0cdad4
/*jslint nomen: true*/
/*global RSVP, jiodate*/
(
function
(
jIO
)
{
"
use strict
"
;
// Used to distinguish between operations done within the same millisecond
var
unique_timestamp
=
function
()
{
// XXX: replace this with UUIDStorage function call to S4() when it becomes
// publicly accessible
var
uuid
=
(
'
0000
'
+
Math
.
floor
(
Math
.
random
()
*
0x10000
)
.
toString
(
16
)).
slice
(
-
4
),
timestamp
=
Date
.
now
().
toString
();
return
timestamp
+
"
-
"
+
uuid
;
};
/**
* The jIO BryanStorage extension
*
* @class BryanStorage
* @constructor
*/
function
BryanStorage
(
spec
)
{
this
.
_sub_storage
=
jIO
.
createJIO
({
type
:
"
query
"
,
sub_storage
:
spec
.
sub_storage
});
}
BryanStorage
.
prototype
.
get
=
function
(
id_in
)
{
// Query to get the last edit made to this document
var
substorage
=
this
.
_sub_storage
,
options
=
{
query
:
"
doc_id:
"
+
id_in
,
sort_on
:
[[
"
timestamp
"
,
"
descending
"
]],
limit
:
[
0
,
1
]
};
return
substorage
.
allDocs
(
options
)
.
push
(
function
(
results
)
{
if
(
results
.
data
.
rows
.
length
>
0
)
{
return
substorage
.
get
(
results
.
data
.
rows
[
0
].
id
);
}
throw
new
jIO
.
util
.
jIOError
(
"
bryanstorage: cannot find object '
"
+
id_in
+
"
'
"
,
404
);
})
.
push
(
function
(
result
)
{
if
(
result
.
op
===
"
put
"
)
{
return
result
.
doc
;
}
throw
new
jIO
.
util
.
jIOError
(
"
bryanstorage: cannot find object '
"
+
id_in
+
"
' (removed)
"
,
404
);
// If no documents returned in first query, check if the id is encoding
// revision information
},
function
()
{
var
steps
,
steps_loc
=
id_in
.
lastIndexOf
(
"
_-
"
);
// If revision signature is not in id_in, than return 404, since id
// is not found
if
(
steps_loc
===
-
1
)
{
throw
new
jIO
.
util
.
jIOError
(
"
bryanstorage: cannot find object '
"
+
id_in
+
"
'
"
,
404
);
}
// If revision signature is found, query storage based on this
steps
=
Number
(
id_in
.
slice
(
steps_loc
+
2
));
id_in
=
id_in
.
slice
(
0
,
steps_loc
);
options
=
{
query
:
"
doc_id:
"
+
id_in
,
sort_on
:
[[
"
timestamp
"
,
"
descending
"
]],
limit
:
[
steps
,
1
]
};
return
substorage
.
allDocs
(
options
)
.
push
(
function
(
results
)
{
if
(
results
.
data
.
rows
.
length
>
0
)
{
return
substorage
.
get
(
results
.
data
.
rows
[
0
].
id
);
}
throw
new
jIO
.
util
.
jIOError
(
"
bryanstorage: cannot find object '
"
+
id_in
+
"
'
"
,
404
);
})
.
push
(
function
(
result
)
{
if
(
result
.
op
===
"
put
"
)
{
return
result
.
doc
;
}
throw
new
jIO
.
util
.
jIOError
(
"
bryanstorage: cannot find object '
"
+
id_in
+
"
' (removed)
"
,
404
);
});
});
};
BryanStorage
.
prototype
.
post
=
function
(
metadata
)
{
return
this
.
_sub_storage
.
post
(
metadata
);
};
BryanStorage
.
prototype
.
put
=
function
(
id
,
data
)
{
var
timestamp
=
unique_timestamp
(),
metadata
=
{
// XXX: remove this attribute once query can sort_on id
timestamp
:
timestamp
,
doc_id
:
id
,
doc
:
data
,
op
:
"
put
"
};
return
this
.
_sub_storage
.
put
(
timestamp
,
metadata
);
};
BryanStorage
.
prototype
.
remove
=
function
(
id
)
{
var
timestamp
=
unique_timestamp
(),
metadata
=
{
// XXX: remove this attribute once query can sort_on id
timestamp
:
timestamp
,
doc_id
:
id
,
op
:
"
remove
"
};
return
this
.
_sub_storage
.
put
(
timestamp
,
metadata
);
};
BryanStorage
.
prototype
.
allAttachments
=
function
()
{
return
this
.
_sub_storage
.
allAttachments
.
apply
(
this
.
_sub_storage
,
arguments
);
};
BryanStorage
.
prototype
.
getAttachment
=
function
()
{
return
this
.
_sub_storage
.
getAttachment
.
apply
(
this
.
_sub_storage
,
arguments
);
};
BryanStorage
.
prototype
.
putAttachment
=
function
(
id
,
name
,
data
)
{
// Save pointer to substorage for use in nested function
var
substorage
=
this
.
_sub_storage
;
// First, get document metadata to update "_revision"
return
this
.
get
(
id
,
name
)
// Increment "_revision" parameter in document
.
push
(
function
(
metadata
)
{
var
new_metadata
=
metadata
;
// "_revision" is guaranteed to exist since the document already exists
new_metadata
.
_revision
=
metadata
.
_revision
+
1
;
return
substorage
.
put
(
id
,
new_metadata
);
})
// After metadata updates successfully, perform putAttachment
.
push
(
function
()
{
return
substorage
.
putAttachment
(
id
,
name
,
data
);
});
};
BryanStorage
.
prototype
.
removeAttachment
=
function
(
id
,
name
)
{
// Save pointer to substorage for use in nested function
var
substorage
=
this
.
_sub_storage
;
// First, get document metadata to update "_revision"
return
this
.
get
(
id
,
name
)
// Increment "_revision" parameter in document
.
push
(
function
(
metadata
)
{
var
new_metadata
=
metadata
;
// "_revision" is guaranteed to exist since the document already exists
new_metadata
.
_revision
=
metadata
.
_revision
+
1
;
return
substorage
.
put
(
id
,
new_metadata
);
})
// After metadata updates successfully, perform removeAttachment
.
push
(
function
()
{
return
substorage
.
removeAttachment
(
id
,
name
);
});
};
BryanStorage
.
prototype
.
repair
=
function
()
{
return
this
.
_sub_storage
.
repair
.
apply
(
this
.
_sub_storage
,
arguments
);
};
BryanStorage
.
prototype
.
hasCapacity
=
function
()
{
return
this
.
_sub_storage
.
hasCapacity
.
apply
(
this
.
_sub_storage
,
arguments
);
};
BryanStorage
.
prototype
.
buildQuery
=
function
(
options
)
{
if
(
options
===
undefined
)
{
options
=
{};
}
if
(
options
.
query
===
undefined
)
{
options
.
query
=
""
;
}
options
.
query
=
jIO
.
QueryFactory
.
create
(
options
.
query
);
var
meta_options
=
{
// XXX: I don't believe it's currently possible to query on
// sub-attributes so for now, we just use the inputted query, which
// obviously will fail
query
:
""
,
// XXX: same here, we cannot sort correctly because we cannot access
// attributes of doc
sort_on
:
[[
"
timestamp
"
,
"
descending
"
]]
},
substorage
=
this
.
_sub_storage
,
// Check if query involved _REVISION. If not, we will later place a
// (*) AND (_REVISION: =0) as the default handling of revisions
rev_query
=
false
,
query_obj
=
options
.
query
,
query_stack
=
[],
ind
;
if
(
query_obj
.
hasOwnProperty
(
"
query_list
"
))
{
query_stack
.
push
(
query_obj
);
}
else
{
rev_query
=
(
query_obj
.
key
===
"
_REVISION
"
);
}
while
(
query_stack
.
length
>
0
&&
(
!
rev_query
))
{
query_obj
=
query_stack
.
pop
();
for
(
ind
=
0
;
ind
<
query_obj
.
query_list
.
length
;
ind
+=
1
)
{
if
(
query_obj
.
query_list
[
ind
].
hasOwnProperty
(
"
query_list
"
))
{
query_stack
.
push
(
query_obj
.
query_list
[
ind
]);
}
else
if
(
query_obj
.
query_list
[
ind
].
key
===
"
_REVISION
"
)
{
rev_query
=
true
;
break
;
}
}
}
return
this
.
_sub_storage
.
allDocs
(
meta_options
)
// Get all documents found in query
.
push
(
function
(
results
)
{
var
promises
=
results
.
data
.
rows
.
map
(
function
(
data
)
{
return
substorage
.
get
(
data
.
id
);
});
return
RSVP
.
all
(
promises
);
})
.
push
(
function
(
results
)
{
// Label all documents with their current revision status
var
doc
,
revision_tracker
=
{},
promises
;
for
(
ind
=
0
;
ind
<
results
.
length
;
ind
+=
1
)
{
doc
=
results
[
ind
];
if
(
revision_tracker
.
hasOwnProperty
(
doc
.
doc_id
))
{
revision_tracker
[
doc
.
doc_id
]
+=
1
;
}
else
{
revision_tracker
[
doc
.
doc_id
]
=
0
;
}
doc
.
_REVISION
=
revision_tracker
[
doc
.
doc_id
];
}
// There must be a faster way
promises
=
results
.
map
(
function
(
data
)
{
return
substorage
.
put
(
data
.
timestamp
,
data
);
});
return
RSVP
.
all
(
promises
);
})
.
push
(
function
()
{
var
latest_rev_query
;
latest_rev_query
=
jIO
.
QueryFactory
.
create
(
"
(_REVISION: >= 0) AND (NOT op: remove)
"
);
if
(
rev_query
)
{
latest_rev_query
.
query_list
[
0
]
=
options
.
query
;
}
else
{
latest_rev_query
.
query_list
[
0
]
=
jIO
.
QueryFactory
.
create
(
"
(_REVISION: =0)
"
);
if
(
options
.
query
.
type
===
"
simple
"
||
options
.
query
.
type
===
"
complex
"
)
{
latest_rev_query
.
query_list
.
push
(
options
.
query
);
}
}
// Build a query for final push
options
.
query
=
latest_rev_query
;
if
(
options
.
sort_on
===
undefined
)
{
options
.
sort_on
=
[];
}
options
.
sort_on
.
push
([
"
timestamp
"
,
"
descending
"
]);
return
substorage
.
allDocs
(
options
);
})
.
push
(
function
(
results
)
{
var
promises
=
results
.
data
.
rows
.
map
(
function
(
data
)
{
return
substorage
.
get
(
data
.
id
);
});
return
RSVP
.
all
(
promises
);
})
.
push
(
function
(
results
)
{
return
results
.
map
(
function
(
current_doc
)
{
return
{
doc
:
current_doc
.
doc
,
value
:
{},
id
:
current_doc
.
doc_id
};
});
});
};
jIO
.
addStorage
(
'
bryan
'
,
BryanStorage
);
}(
jIO
));
\ No newline at end of file
test/jio.storage/bryanstorage.tests.js
deleted
100644 → 0
View file @
7b0cdad4
/*jslint nomen: true*/
/*global Blob, jiodate*/
(
function
(
jIO
,
QUnit
)
{
"
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
;
/////////////////////////////////////////////////////////////////
// _revision parameter updating with RSVP all
/////////////////////////////////////////////////////////////////
module
(
"
bryanStorage.revision_with_RSVP_all
"
);
test
(
"
verifying updates correctly when puts are done in parallel
"
,
function
()
{
stop
();
expect
(
7
);
// create storage of type "bryan" with memory as substorage
var
dbname
=
"
rsvp_db_
"
+
Date
.
now
(),
jio
=
jIO
.
createJIO
({
type
:
"
bryan
"
,
sub_storage
:
{
type
:
"
uuid
"
,
sub_storage
:
{
//type: "memory"
type
:
"
indexeddb
"
,
database
:
dbname
}
}
}),
not_bryan
=
jIO
.
createJIO
({
type
:
"
query
"
,
sub_storage
:
{
type
:
"
uuid
"
,
sub_storage
:
{
//type: "memory"
type
:
"
indexeddb
"
,
database
:
dbname
}
}
});
jio
.
put
(
"
bar
"
,
{
"
title
"
:
"
foo0
"
})
.
push
(
function
()
{
return
RSVP
.
all
([
jio
.
put
(
"
bar
"
,
{
"
title
"
:
"
foo1
"
}),
jio
.
put
(
"
bar
"
,
{
"
title
"
:
"
foo2
"
}),
jio
.
put
(
"
bar
"
,
{
"
title
"
:
"
foo3
"
}),
jio
.
put
(
"
bar
"
,
{
"
title
"
:
"
foo4
"
}),
jio
.
put
(
"
barbar
"
,
{
"
title
"
:
"
attr0
"
}),
jio
.
put
(
"
barbar
"
,
{
"
title
"
:
"
attr1
"
}),
jio
.
put
(
"
barbar
"
,
{
"
title
"
:
"
attr2
"
}),
jio
.
put
(
"
barbar
"
,
{
"
title
"
:
"
attr3
"
})
]);
})
.
push
(
function
()
{
return
jio
.
get
(
"
bar
"
);
})
.
push
(
function
(
result
)
{
ok
(
result
.
title
!==
"
foo0
"
,
"
Title should have changed from foo0
"
);
})
.
push
(
function
()
{
return
not_bryan
.
allDocs
({
query
:
""
,
sort_on
:
[[
"
timestamp
"
,
"
ascending
"
]]
});
})
.
push
(
function
(
results
)
{
equal
(
results
.
data
.
rows
.
length
,
9
,
"
All nine versions exist in storage
"
);
return
not_bryan
.
get
(
results
.
data
.
rows
[
0
].
id
);
})
.
push
(
function
(
results
)
{
deepEqual
(
results
,
{
doc_id
:
"
bar
"
,
doc
:
{
title
:
"
foo0
"
},
timestamp
:
results
.
timestamp
,
op
:
"
put
"
},
"
The first item in the log is pushing bar's title to 'foo0'
"
);
return
jio
.
remove
(
"
bar
"
);
})
.
push
(
function
()
{
return
jio
.
get
(
"
bar
"
);
})
.
push
(
function
()
{
return
jio
.
get
(
"
barbar
"
);
},
function
(
error
)
{
deepEqual
(
error
.
message
,
"
bryanstorage: cannot find object 'bar' (removed)
"
,
"
Appropriate error is sent explaining object has been removed
"
);
return
jio
.
get
(
"
barbar
"
);
})
.
push
(
function
(
result
)
{
ok
(
result
.
title
!==
undefined
,
"
barbar exists and has proper form
"
);
return
not_bryan
.
allDocs
({
query
:
""
,
sort_on
:
[[
"
op
"
,
"
descending
"
]]
});
})
.
push
(
function
(
results
)
{
equal
(
results
.
data
.
rows
.
length
,
10
,
"
Remove operation is recorded
"
);
return
not_bryan
.
get
(
results
.
data
.
rows
[
0
].
id
);
})
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
doc_id
:
"
bar
"
,
timestamp
:
result
.
timestamp
,
op
:
"
remove
"
});
})
.
fail
(
function
(
error
)
{
//console.log(error);
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
/////////////////////////////////////////////////////////////////
// bryanStorage.querying_from_bryanstorage
/////////////////////////////////////////////////////////////////
module
(
"
bryanStorage.querying_from_bryanstorage
"
);
test
(
"
verifying the correct results are returned from bryanStorage.allDocs
"
,
function
()
{
stop
();
expect
(
10
);
// create storage of type "bryan" with memory as substorage
var
jio
=
jIO
.
createJIO
({
type
:
"
bryan
"
,
sub_storage
:
{
type
:
"
uuid
"
,
sub_storage
:
{
type
:
"
memory
"
}
}
});
jio
.
put
(
"
bar
"
,
{
"
title
"
:
"
foo0
"
})
.
push
(
function
()
{
return
RSVP
.
all
([
jio
.
remove
(
"
bar
"
),
jio
.
put
(
"
bar
"
,
{
"
title
"
:
"
foo1
"
}),
jio
.
put
(
"
bar
"
,
{
"
title
"
:
"
foo2
"
}),
jio
.
put
(
"
bar
"
,
{
"
title
"
:
"
foo3
"
}),
jio
.
put
(
"
barbar
"
,
{
"
title
"
:
"
attr0
"
}),
jio
.
put
(
"
barbar
"
,
{
"
title
"
:
"
attr1
"
}),
jio
.
put
(
"
barbar
"
,
{
"
title
"
:
"
attr2
"
}),
jio
.
put
(
"
barbarbar
"
,
{
"
title
"
:
"
val0
"
}),
jio
.
put
(
"
barbarbarbar
"
,
{
"
title
"
:
"
prop0
"
})
]);
})
// Make two final puts so we know what to expect as the current state of
// each document.
.
push
(
function
()
{
return
jio
.
put
(
"
barbar
"
,
{
"
title
"
:
"
attr3
"
});
})
.
push
(
function
()
{
return
jio
.
put
(
"
bar
"
,
{
"
title
"
:
"
foo4
"
});
})
// Queries should only include information about the final two versions
.
push
(
function
()
{
return
jio
.
allDocs
({
query
:
""
,
sort_on
:
[[
"
title
"
,
"
ascending
"
]]
});
})
.
push
(
function
(
results
)
{
equal
(
results
.
data
.
rows
.
length
,
4
,
"
Empty query yields four results since there are four unique docs
"
);
return
jio
.
get
(
results
.
data
.
rows
[
0
].
id
);
},
function
(
error
)
{
return
ok
(
false
,
"
Query failed:
"
+
error
);
})
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
title
:
"
attr3
"
},
"
NOT IMPLEMENTED: Retrieve correct sort order with no metadata
"
);
},
function
()
{
return
ok
(
false
,
"
Couldn't find document in storage
"
);
})
// Querying with a limit
.
push
(
function
()
{
return
jio
.
allDocs
({
query
:
""
,
sort_on
:
[[
"
title
"
,
"
ascending
"
]],
limit
:
[
0
,
1
]
});
})
.
push
(
function
(
results
)
{
equal
(
results
.
data
.
rows
.
length
,
1
,
"
Since limit [0,1] was supplied, only 1st document is returned
"
);
return
jio
.
get
(
results
.
data
.
rows
[
0
].
id
);
})
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
title
:
"
attr3
"
},
"
NOT IMPLEMENTED: retrieving documents in specified sort_on order
"
);
})
// Querying with a more complicated limit
.
push
(
function
()
{
return
jio
.
allDocs
({
query
:
""
,
sort_on
:
[[
"
title
"
,
"
ascending
"
]],
limit
:
[
2
,
2
]
});
})
.
push
(
function
(
results
)
{
equal
(
results
.
data
.
rows
.
length
,
2
,
"
Retrieving the correct documents when options.limit is specified
"
);
deepEqual
(
results
.
data
.
rows
[
0
].
id
,
"
barbarbarbar
"
,
"
NOT IMPLEMENTED: retrieving documents in specified sort_on order
"
);
deepEqual
(
results
.
data
.
rows
[
1
].
id
,
"
barbarbar
"
,
"
NOT IMPLEMENTED: retrieving documents in specified sort_on order
"
);
return
jio
.
get
(
results
.
data
.
rows
[
0
].
id
);
})
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
title
:
"
property0
"
},
"
NOT IMPLEMENTED: retrieving documents in specified sort_on order
"
);
})
// Querying for a specific id
.
push
(
function
()
{
return
jio
.
allDocs
({
query
:
"
id: bar
"
});
})
.
push
(
function
(
results
)
{
equal
(
results
.
data
.
rows
.
length
,
1
,
"
NOT IMPLEMENTED: query involving specific document attributes
"
);
return
jio
.
get
(
results
.
data
.
rows
[
0
].
id
);
})
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
title
:
"
foo4
"
},
"
NOT IMPLEMENTED: query involving specific document attributes
"
);
},
function
()
{
ok
(
false
,
"
NOT IMPLEMENTED: query involving specific document attributes
"
);
})
.
fail
(
function
(
error
)
{
//console.log(error);
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
/////////////////////////////////////////////////////////////////
// Accessing older revisions
/////////////////////////////////////////////////////////////////
module
(
"
bryanStorage.accessing_older_revisions
"
);
test
(
"
Testing proper retrieval of older revisions of documents
"
,
function
()
{
stop
();
expect
(
18
);
// create storage of type "bryan" with memory as substorage
var
jio
=
jIO
.
createJIO
({
type
:
"
bryan
"
,
sub_storage
:
{
type
:
"
uuid
"
,
sub_storage
:
{
type
:
"
memory
"
}
}
});
jio
.
get
(
"
doc
"
)
.
push
(
function
()
{
ok
(
false
,
"
This query should have thrown a 404 error
"
);
},
function
(
error
)
{
deepEqual
(
error
.
status_code
,
404
,
"
Document does not exist yet.
"
);
})
.
push
(
function
()
{
return
jio
.
put
(
"
doc
"
,
{
"
k0
"
:
"
v0
"
});
})
.
push
(
function
()
{
return
jio
.
get
(
"
doc_-0
"
);
})
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
"
k0
"
:
"
v0
"
});
})
.
push
(
function
()
{
return
jio
.
put
(
"
doc
"
,
{
"
k1
"
:
"
v1
"
});
})
.
push
(
function
()
{
return
jio
.
get
(
"
doc_-0
"
);
})
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
"
k1
"
:
"
v1
"
});
})
.
push
(
function
()
{
return
jio
.
get
(
"
doc_-1
"
);
})
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
"
k0
"
:
"
v0
"
});
})
.
push
(
function
()
{
return
jio
.
put
(
"
doc
"
,
{
"
k2
"
:
"
v2
"
});
})
.
push
(
function
()
{
return
jio
.
remove
(
"
doc
"
);
})
.
push
(
function
()
{
return
jio
.
put
(
"
doc
"
,
{
"
k3
"
:
"
v3
"
});
})
.
push
(
function
()
{
return
jio
.
put
(
"
doc
"
,
{
"
k4
"
:
"
v4
"
});
})
.
push
(
function
()
{
return
jio
.
get
(
"
doc
"
);
})
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
"
k4
"
:
"
v4
"
},
"
By default, .get returns latest revision
"
);
return
jio
.
get
(
"
doc
"
);
})
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
"
k4
"
:
"
v4
"
},
"
.get returns latest revision with second input = 0
"
);
return
jio
.
get
(
"
doc_-1
"
);
})
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
"
k3
"
:
"
v3
"
},
"
Walk back one revision with second input = 1
"
);
return
jio
.
get
(
"
doc_-2
"
);
})
.
push
(
function
()
{
ok
(
false
,
"
This query should have thrown a 404 error
"
);
},
function
(
error
)
{
deepEqual
(
error
.
status_code
,
404
,
"
Current state of document is 'removed'.
"
);
return
jio
.
get
(
"
doc_-3
"
);
})
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
"
k2
"
:
"
v2
"
},
"
Walk back three revisions with second input = 3
"
);
return
jio
.
get
(
"
doc_-4
"
);
})
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
"
k1
"
:
"
v1
"
},
"
Walk back four revisions with second input = 4
"
);
return
jio
.
get
(
"
doc_-5
"
);
})
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
"
k0
"
:
"
v0
"
},
"
Walk back five revisions with second input = 5
"
);
return
jio
.
get
(
"
doc_-6
"
);
})
.
push
(
function
()
{
ok
(
false
,
"
This query should have thrown a 404 error
"
);
},
function
(
error
)
{
deepEqual
(
error
.
status_code
,
404
,
"
There are only 5 previous states of this document
"
);
})
// Adding documents with problematic doc_id's
.
push
(
function
()
{
return
jio
.
put
(
"
doc_-name
"
,
{
"
key
"
:
"
val0
"
});
})
.
push
(
function
()
{
return
jio
.
put
(
"
document_-0
"
,
{
"
key
"
:
"
and val0
"
});
})
.
push
(
function
()
{
return
jio
.
put
(
"
doc_-name
"
,
{
"
key
"
:
"
val1
"
});
})
.
push
(
function
()
{
return
jio
.
get
(
"
doc_-name
"
);
})
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
"
key
"
:
"
val1
"
});
return
jio
.
get
(
"
doc_-name_-0
"
);
})
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
"
key
"
:
"
val1
"
});
return
jio
.
get
(
"
doc_-name_-1
"
);
})
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
"
key
"
:
"
val0
"
});
return
jio
.
get
(
"
document_-0
"
);
})
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
"
key
"
:
"
and val0
"
});
return
jio
.
get
(
"
document_-0_-0
"
);
})
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
"
key
"
:
"
and val0
"
});
return
jio
.
get
(
"
document_-0_-1
"
);
})
.
push
(
function
()
{
ok
(
false
,
"
This query should have thrown a 404 error
"
);
},
function
(
error
)
{
deepEqual
(
error
.
status_code
,
404
,
"
Document does not have this many revisions.
"
);
})
.
fail
(
function
(
error
)
{
//console.log(error);
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
/////////////////////////////////////////////////////////////////
// Querying older revisions
/////////////////////////////////////////////////////////////////
module
(
"
bryanStorage.querying_old_revisions
"
);
test
(
"
Testing retrieval of older revisions via allDocs calls
"
,
function
()
{
stop
();
expect
(
37
);
// create storage of type "bryan" with memory as substorage
var
jio
=
jIO
.
createJIO
({
type
:
"
bryan
"
,
sub_storage
:
{
type
:
"
uuid
"
,
sub_storage
:
{
type
:
"
memory
"
}
}
});
jio
.
put
(
"
doc
"
,
{
"
k
"
:
"
v0
"
})
.
push
(
function
()
{
return
jio
.
put
(
"
doc
"
,
{
"
k
"
:
"
v1
"
});
})
.
push
(
function
()
{
return
jio
.
put
(
"
doc
"
,
{
"
k
"
:
"
v2
"
});
})
.
push
(
function
()
{
return
jio
.
put
(
"
doc
"
,
{
"
k
"
:
"
v3
"
});
})
.
push
(
function
()
{
return
jio
.
allDocs
({
query
:
"
_REVISION : 0
"
});
})
.
push
(
function
(
results
)
{
deepEqual
(
results
.
data
.
rows
.
length
,
1
,
"
Only one query returned with options.revision_limit == [0,1]
"
);
return
jio
.
get
(
results
.
data
.
rows
[
0
].
id
);
})
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
"
k
"
:
"
v3
"
});
})
.
push
(
function
()
{
return
jio
.
allDocs
({
query
:
"
_REVISION : =1
"
});
})
.
push
(
function
(
results
)
{
deepEqual
(
results
.
data
.
rows
.
length
,
1
,
"
Only one query returned with options.revision_limit == [1,1]
"
);
deepEqual
(
results
.
data
.
rows
[
0
].
doc
,
{
"
k
"
:
"
v2
"
});
return
jio
.
allDocs
({
query
:
"
_REVISION : =2
"
});
})
.
push
(
function
(
results
)
{
deepEqual
(
results
.
data
.
rows
.
length
,
1
,
"
Only one query returned with options.revision_limit == [2,1]
"
);
deepEqual
(
results
.
data
.
rows
[
0
].
doc
,
{
"
k
"
:
"
v1
"
});
return
jio
.
allDocs
({
query
:
"
_REVISION : =3
"
});
})
.
push
(
function
(
results
)
{
deepEqual
(
results
.
data
.
rows
.
length
,
1
,
"
Only one query returned with options.revision_limit == [3,1]
"
);
deepEqual
(
results
.
data
.
rows
[
0
].
doc
,
{
"
k
"
:
"
v0
"
});
return
jio
.
allDocs
({
query
:
"
_REVISION : =4
"
});
})
.
push
(
function
(
results
)
{
equal
(
results
.
data
.
rows
.
length
,
0
,
"
Past all previous revisions
"
);
})
.
push
(
function
()
{
return
jio
.
allDocs
({
query
:
"
_REVISION: <= 1
"
});
})
.
push
(
function
(
results
)
{
equal
(
results
.
data
.
rows
.
length
,
2
);
deepEqual
(
results
.
data
.
rows
[
0
].
doc
,
{
"
k
"
:
"
v3
"
},
"
Only retrieve two most recent revions
"
);
deepEqual
(
results
.
data
.
rows
[
1
].
doc
,
{
"
k
"
:
"
v2
"
});
})
.
push
(
function
()
{
return
jio
.
remove
(
"
doc
"
);
})
.
push
(
function
()
{
return
jio
.
allDocs
({
query
:
"
NOT (_REVISION: >= 1)
"
,
revision_limit
:
[
0
,
1
]
});
})
.
push
(
function
(
results
)
{
equal
(
results
.
data
.
rows
.
length
,
0
,
"
Query does not return removed doc
"
);
})
.
push
(
function
()
{
return
jio
.
allDocs
({
query
:
"
(_REVISION: >= 1) AND (_REVISION: <= 3)
"
});
})
.
push
(
function
(
results
)
{
equal
(
results
.
data
.
rows
.
length
,
3
);
deepEqual
(
results
.
data
.
rows
[
0
].
doc
,
{
"
k
"
:
"
v3
"
},
"
1st, 2nd, and 3rd versions removed from current are retrieved
"
);
deepEqual
(
results
.
data
.
rows
[
1
].
doc
,
{
"
k
"
:
"
v2
"
},
"
1st, 2nd, and 3rd versions removed from current are retrieved
"
);
deepEqual
(
results
.
data
.
rows
[
2
].
doc
,
{
"
k
"
:
"
v1
"
},
"
1st, 2nd, and 3rd versions removed from current are retrieved
"
);
})
.
push
(
function
()
{
return
jio
.
put
(
"
doc2
"
,
{
"
k2
"
:
"
w0
"
});
})
.
push
(
function
()
{
return
jio
.
allDocs
({
query
:
"
(_REVISION: >0) AND (_REVISION: <= 3)
"
});
})
.
push
(
function
(
results
)
{
equal
(
results
.
data
.
rows
.
length
,
3
);
deepEqual
(
results
.
data
.
rows
[
0
].
doc
,
{
"
k
"
:
"
v3
"
},
"
Does not retrieve new document outside queried revision range
"
);
deepEqual
(
results
.
data
.
rows
[
1
].
doc
,
{
"
k
"
:
"
v2
"
},
"
Does not retrieve new document outside queried revision range
"
);
deepEqual
(
results
.
data
.
rows
[
2
].
doc
,
{
"
k
"
:
"
v1
"
},
"
Does not retrieve new document outside queried revision range
"
);
})
.
push
(
function
()
{
return
jio
.
allDocs
({
query
:
"
(_REVISION: = 0) OR (_REVISION: = 1)
"
});
})
.
push
(
function
(
results
)
{
equal
(
results
.
data
.
rows
.
length
,
2
);
deepEqual
(
results
.
data
.
rows
[
0
].
doc
,
{
"
k2
"
:
"
w0
"
},
"
Retrieves all documents with versions in queried revision range
"
);
deepEqual
(
results
.
data
.
rows
[
1
].
doc
,
{
"
k
"
:
"
v3
"
},
"
Retrieves all documents with versions in queried revision range
"
);
})
.
push
(
function
()
{
return
jio
.
put
(
"
doc2
"
,
{
"
k2
"
:
"
w1
"
});
})
.
push
(
function
()
{
return
jio
.
allDocs
();
})
.
push
(
function
(
results
)
{
equal
(
results
.
data
.
rows
.
length
,
1
,
"
There is only one non-removed doc
"
);
deepEqual
(
results
.
data
.
rows
[
0
].
doc
,
{
"
k2
"
:
"
w1
"
});
})
.
push
(
function
()
{
return
jio
.
remove
(
"
doc2
"
);
})
.
push
(
function
()
{
return
jio
.
allDocs
({
query
:
"
_REVISION: 0 OR _REVISION: 1 OR
"
+
"
(_REVISION: >= 2 AND _REVISION: <= 3)
"
});
})
.
push
(
function
(
results
)
{
equal
(
results
.
data
.
rows
.
length
,
5
);
deepEqual
(
results
.
data
.
rows
[
0
].
doc
,
{
"
k2
"
:
"
w1
"
});
deepEqual
(
results
.
data
.
rows
[
1
].
doc
,
{
"
k2
"
:
"
w0
"
});
deepEqual
(
results
.
data
.
rows
[
2
].
doc
,
{
"
k
"
:
"
v3
"
});
deepEqual
(
results
.
data
.
rows
[
3
].
doc
,
{
"
k
"
:
"
v2
"
});
deepEqual
(
results
.
data
.
rows
[
4
].
doc
,
{
"
k
"
:
"
v1
"
});
})
.
push
(
function
()
{
return
jio
.
allDocs
({
query
:
"
_REVISION: <= 3
"
,
limit
:
[
1
,
4
]
});
})
.
push
(
function
(
results
)
{
equal
(
results
.
data
.
rows
.
length
,
4
,
"
Correct number of results with optins.limit set
"
);
deepEqual
(
results
.
data
.
rows
[
0
].
doc
,
{
"
k2
"
:
"
w0
"
},
"
Correct results with options.limit set
"
);
deepEqual
(
results
.
data
.
rows
[
1
].
doc
,
{
"
k
"
:
"
v3
"
},
"
Correct results with options.limit set
"
);
deepEqual
(
results
.
data
.
rows
[
2
].
doc
,
{
"
k
"
:
"
v2
"
},
"
Correct results with options.limit set
"
);
deepEqual
(
results
.
data
.
rows
[
3
].
doc
,
{
"
k
"
:
"
v1
"
},
"
Correct results with options.limit set
"
);
})
.
fail
(
function
(
error
)
{
//console.log(error);
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
}(
jIO
,
QUnit
));
\ No newline at end of file
test/tests.html
View file @
5f5edb5f
...
...
@@ -60,15 +60,15 @@
<script src="../src/jio.storage/xwikistorage.js"></script>
<script src="jio.storage/xwikistorage.tests.js"></script-->
<script
src=
"jio.storage/
bryan
storage.tests.js"
></script>
<script
src=
"jio.storage/
history
storage.tests.js"
></script>
<!--<script src="../src/jio.storage/revisionstorage.js"></script>
<script src="../test/jio.storage/revisionstorage.tests.js"></script>-->
<!--script src="../src/jio.storage/gidstorage.js"></script>
<script src="../test/jio.storage/gidstorage.tests.js"></script>
<script src="../src/jio.storage/revisionstorage.js"></script>
<script src="../test/jio.storage/revisionstorage.tests.js"></script>
<script src="../src/jio.storage/replicaterevisionstorage.js"></script>
<script src="../test/jio.storage/replicaterevisionstorage.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