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
22aba909
Commit
22aba909
authored
Jun 07, 2018
by
Bryan Kaperick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added an optional second parameter for .get to allow access to previous revisions of a document.
parent
6b8af9e6
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
112 additions
and
3 deletions
+112
-3
src/jio.storage/bryanstorage.js
src/jio.storage/bryanstorage.js
+10
-3
test/jio.storage/bryanstorage.tests.js
test/jio.storage/bryanstorage.tests.js
+102
-0
No files found.
src/jio.storage/bryanstorage.js
View file @
22aba909
...
@@ -3,8 +3,11 @@
...
@@ -3,8 +3,11 @@
(
function
(
jIO
)
{
(
function
(
jIO
)
{
"
use strict
"
;
"
use strict
"
;
var
unique_timestamp
=
function
()
{
// Used to distinguish between operations done within the same millisecond
// 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
)
var
uuid
=
(
'
0000
'
+
Math
.
floor
(
Math
.
random
()
*
0x10000
)
.
toString
(
16
)).
slice
(
-
4
),
.
toString
(
16
)).
slice
(
-
4
),
timestamp
=
Date
.
now
().
toString
();
timestamp
=
Date
.
now
().
toString
();
...
@@ -25,14 +28,18 @@
...
@@ -25,14 +28,18 @@
});
});
}
}
BryanStorage
.
prototype
.
get
=
function
(
id_in
)
{
BryanStorage
.
prototype
.
get
=
function
(
id_in
,
revision_steps
)
{
// Default behavior, get() returns the most recent revision
if
(
revision_steps
===
undefined
)
{
revision_steps
=
0
;
}
// Query to get the last edit made to this document
// Query to get the last edit made to this document
var
substorage
=
this
.
_sub_storage
,
var
substorage
=
this
.
_sub_storage
,
options
=
{
options
=
{
query
:
"
doc_id:
"
+
id_in
,
query
:
"
doc_id:
"
+
id_in
,
sort_on
:
[[
"
timestamp
"
,
"
descending
"
]],
sort_on
:
[[
"
timestamp
"
,
"
descending
"
]],
limit
:
[
0
,
1
]
limit
:
[
revision_steps
,
1
]
};
};
return
substorage
.
allDocs
(
options
)
return
substorage
.
allDocs
(
options
)
.
push
(
function
(
results
)
{
.
push
(
function
(
results
)
{
...
...
test/jio.storage/bryanstorage.tests.js
View file @
22aba909
...
@@ -278,4 +278,106 @@
...
@@ -278,4 +278,106 @@
})
})
.
always
(
function
()
{
start
();
});
.
always
(
function
()
{
start
();
});
});
});
/////////////////////////////////////////////////////////////////
// Accessing older revisions
/////////////////////////////////////////////////////////////////
module
(
"
bryanStorage.accessing_older_revisions
"
);
test
(
"
Testing proper retrieval of older revisions of documents
"
,
function
()
{
stop
();
expect
(
8
);
// 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
"
,
{
"
k0
"
:
"
v0
"
})
.
push
(
function
()
{
return
jio
.
put
(
"
doc
"
,
{
"
k1
"
:
"
v1
"
});
})
.
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
"
,
0
);
})
.
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
"
);
})
.
fail
(
function
(
error
)
{
//console.log(error);
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
}(
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