Skip to content
This repository has been archived by the owner on Apr 4, 2022. It is now read-only.

Remove quotes from last_modified attribute in listRecords() #110

Merged
merged 1 commit into from
Jun 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,7 @@ Sample result:

```js
{
last_modified: "\"1456183930780\"",
last_modified: "1456183930780",
next: <Function>,
data: [
{
Expand Down Expand Up @@ -1036,7 +1036,7 @@ To retrieve the list of records modified since a given timestamp, use the `since

```js
client.bucket("blog").collection("posts")
.listRecords({since: "\"1456183930780\""})
.listRecords({since: "1456183930780"})
.then(({data, next}) => {
```

Expand Down
5 changes: 3 additions & 2 deletions src/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,16 +290,17 @@ export default class Collection {
};

const pageResults = (results, nextPage, etag) => {
// ETag string is supposed to be opaque and stored «as-is».
// ETag header values are quoted (because of * and W/"foo").
return {
last_modified: etag,
last_modified: etag ? etag.replace(/"/g, "") : etag,
data: results,
next: next.bind(null, nextPage)
};
};

const handleResponse = ({headers, json}) => {
const nextPage = headers.get("Next-Page");
// ETag are supposed to be opaque and stored «as-is».
const etag = headers.get("ETag");
if (!pages) {
return pageResults(json.data, nextPage, etag);
Expand Down
4 changes: 2 additions & 2 deletions test/collection_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,9 @@ describe("Collection", () => {
.to.Throw(Error, /Invalid value for since \(123\), should be ETag value/);
});

it("should resolve with the collection last_modified cast as int value", () => {
it("should resolve with the collection last_modified without quotes", () => {
return coll.listRecords()
.should.eventually.have.property("last_modified").eql(ETag);
.should.eventually.have.property("last_modified").eql("42");
});
});

Expand Down