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
ee3050e4
Commit
ee3050e4
authored
Jul 19, 2018
by
Bryan Kaperick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added new put functionality and tests on put and putAttachment.
parent
3d03aafb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
153 additions
and
2 deletions
+153
-2
src/jio.storage/historystorage.js
src/jio.storage/historystorage.js
+39
-1
test/jio.storage/historystorage.tests.js
test/jio.storage/historystorage.tests.js
+114
-1
No files found.
src/jio.storage/historystorage.js
View file @
ee3050e4
...
@@ -15,6 +15,13 @@
...
@@ -15,6 +15,13 @@
return
timestamp
+
"
-
"
+
uuid
;
return
timestamp
+
"
-
"
+
uuid
;
}
}
function
isTimestamp
(
id
)
{
//A timestamp is of the form
//"[13 digit number]-[4 numbers/lowercase letters]"
var
re
=
/^
[
0-9
]{13}
-
[
a-z0-9
]{4}
$/
;
return
re
.
test
(
id
);
}
function
removeOldRevs
(
function
removeOldRevs
(
substorage
,
substorage
,
results
,
results
,
...
@@ -193,7 +200,8 @@
...
@@ -193,7 +200,8 @@
};
};
HistoryStorage
.
prototype
.
put
=
function
(
id
,
data
)
{
HistoryStorage
.
prototype
.
put
=
function
(
id
,
data
)
{
var
timestamp
=
generateUniqueTimestamp
(
Date
.
now
()),
var
substorage
=
this
.
_sub_storage
,
timestamp
=
generateUniqueTimestamp
(
Date
.
now
()),
metadata
=
{
metadata
=
{
// XXX: remove this attribute once query can sort_on id
// XXX: remove this attribute once query can sort_on id
timestamp
:
timestamp
,
timestamp
:
timestamp
,
...
@@ -201,6 +209,22 @@
...
@@ -201,6 +209,22 @@
doc
:
data
,
doc
:
data
,
op
:
"
put
"
op
:
"
put
"
};
};
if
(
this
.
_include_revisions
&&
isTimestamp
(
id
))
{
return
substorage
.
get
(
id
)
.
push
(
function
(
metadata
)
{
metadata
.
timestamp
=
timestamp
;
metadata
.
doc
=
data
;
return
substorage
.
put
(
timestamp
,
metadata
);
},
function
(
error
)
{
if
(
error
.
status_code
===
404
&&
error
instanceof
jIO
.
util
.
jIOError
)
{
return
substorage
.
put
(
timestamp
,
metadata
);
}
throw
error
;
});
}
return
this
.
_sub_storage
.
put
(
timestamp
,
metadata
);
return
this
.
_sub_storage
.
put
(
timestamp
,
metadata
);
};
};
...
@@ -343,6 +367,20 @@
...
@@ -343,6 +367,20 @@
op
:
"
putAttachment
"
op
:
"
putAttachment
"
},
},
substorage
=
this
.
_sub_storage
;
substorage
=
this
.
_sub_storage
;
if
(
this
.
_include_revisions
&&
isTimestamp
(
id
))
{
return
substorage
.
get
(
id
)
.
push
(
function
(
metadata
)
{
metadata
.
timestamp
=
timestamp
;
metadata
.
name
=
name
;
},
function
(
error
)
{
if
(
!
(
error
.
status_code
===
404
&&
error
instanceof
jIO
.
util
.
jIOError
))
{
throw
error
;
}
});
}
return
this
.
_sub_storage
.
put
(
timestamp
,
metadata
)
return
this
.
_sub_storage
.
put
(
timestamp
,
metadata
)
.
push
(
function
()
{
.
push
(
function
()
{
return
substorage
.
putAttachment
(
timestamp
,
name
,
blob
);
return
substorage
.
putAttachment
(
timestamp
,
name
,
blob
);
...
...
test/jio.storage/historystorage.tests.js
View file @
ee3050e4
...
@@ -832,7 +832,7 @@
...
@@ -832,7 +832,7 @@
})
})
.
push
(
function
(
res
)
{
.
push
(
function
(
res
)
{
timestamp
=
res
.
data
.
rows
[
0
].
id
;
timestamp
=
res
.
data
.
rows
[
0
].
id
;
return
history
.
put
(
timestamp
,
{
key
:
"
val
"
});
return
jio
.
put
(
timestamp
,
{
key
:
"
val
"
});
})
})
.
push
(
function
()
{
.
push
(
function
()
{
return
jio
.
get
(
"
doc
"
);
return
jio
.
get
(
"
doc
"
);
...
@@ -1001,6 +1001,119 @@
...
@@ -1001,6 +1001,119 @@
.
always
(
function
()
{
start
();
});
.
always
(
function
()
{
start
();
});
});
});
test
(
"
Updating a document with include revisions
"
,
function
()
{
stop
();
expect
(
1
);
var
jio
=
this
.
jio
,
history
=
this
.
history
,
not_history
=
this
.
not_history
,
timestamps
,
t_id
;
jio
.
put
(
"
doc
"
,
{
title
:
"
version0
"
})
.
push
(
function
()
{
return
history
.
put
(
"
doc
"
,
{
title
:
"
version1
"
});
})
.
push
(
function
()
{
return
not_history
.
allDocs
({
sort_on
:
[[
"
timestamp
"
,
"
ascending
"
]]});
})
.
push
(
function
(
results
)
{
t_id
=
results
.
data
.
rows
[
0
].
id
;
return
history
.
put
(
t_id
,
{
title
:
"
version0.1
"
});
})
.
push
(
function
()
{
return
jio
.
put
(
t_id
,
{
title
:
"
label0
"
});
})
.
push
(
function
()
{
return
history
.
put
(
"
1234567891012-abcd
"
,
{
k
:
"
v
"
});
})
.
push
(
function
()
{
return
not_history
.
allDocs
({
select_list
:
[
"
timestamp
"
]
});
})
.
push
(
function
(
results
)
{
timestamps
=
results
.
data
.
rows
.
map
(
function
(
d
)
{
return
d
.
value
.
timestamp
;
});
})
.
push
(
function
()
{
return
not_history
.
allDocs
({
sort_on
:
[[
"
timestamp
"
,
"
ascending
"
]],
select_list
:
[
"
timestamp
"
,
"
op
"
,
"
doc_id
"
,
"
doc
"
]
});
})
.
push
(
function
(
results
)
{
deepEqual
(
results
.
data
.
rows
,
[
{
id
:
timestamps
[
0
],
doc
:
{},
value
:
{
timestamp
:
timestamps
[
0
],
op
:
"
put
"
,
doc_id
:
"
doc
"
,
doc
:
{
title
:
"
version0
"
}
}
},
{
id
:
timestamps
[
1
],
doc
:
{},
value
:
{
timestamp
:
timestamps
[
1
],
op
:
"
put
"
,
doc_id
:
"
doc
"
,
doc
:
{
title
:
"
version1
"
}
}
},
{
id
:
timestamps
[
2
],
doc
:
{},
value
:
{
timestamp
:
timestamps
[
2
],
op
:
"
put
"
,
doc_id
:
"
doc
"
,
doc
:
{
title
:
"
version0.1
"
}
}
},
{
id
:
timestamps
[
3
],
doc
:
{},
value
:
{
timestamp
:
timestamps
[
3
],
op
:
"
put
"
,
doc_id
:
timestamps
[
0
],
doc
:
{
title
:
"
label0
"
}
}
},
{
id
:
timestamps
[
4
],
doc
:
{},
value
:
{
timestamp
:
timestamps
[
4
],
op
:
"
put
"
,
doc_id
:
"
1234567891012-abcd
"
,
doc
:
{
k
:
"
v
"
}
}
}
],
"
Documents stored with correct metadata
"
);
})
.
fail
(
function
(
error
)
{
//console.log(error);
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
Retrieving older revisions with get
"
,
test
(
"
Retrieving older revisions with get
"
,
function
()
{
function
()
{
stop
();
stop
();
...
...
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