-
Notifications
You must be signed in to change notification settings - Fork 16
implement #138 since option for collection.getTotalRecords #142
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,13 +79,18 @@ export default class Collection { | |
* | ||
* @param {Object} [options={}] The options object. | ||
* @param {Object} [options.headers] The headers object option. | ||
* @param {String} [options.since] The since ETag option. | ||
* @return {Promise<Number, Error>} | ||
*/ | ||
getTotalRecords(options={}) { | ||
const { headers } = this._collOptions(options); | ||
let path = endpoint("record", this.bucket.name, this.name); | ||
if(options.since){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: space after |
||
path += "?since="+options.since; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It may be nice to reuse the Also nit: space around operand |
||
} | ||
return this.client.execute({ | ||
method: "HEAD", | ||
path: endpoint("record", this.bucket.name, this.name), | ||
path: path, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I insist on this, pretty please: return this.client.execute({
method: "HEAD",
path,
headers,
}, {raw: true}) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've used path directly. Is there something else to do? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's basically the difference between: return this.client.execute({
method: "HEAD",
path: path,
headers,
}, {raw: true}) and return this.client.execute({
method: "HEAD",
path,
headers,
}, {raw: true}) |
||
headers | ||
}, {raw: true}) | ||
.then(({headers}) => parseInt(headers.get("Total-Records"), 10)); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,18 @@ describe("Collection", () => { | |
return getBlogPostsCollection().getTotalRecords() | ||
.should.become(42); | ||
}); | ||
|
||
it("should pass the since parameter", () => { | ||
sandbox.stub(client, "execute").returns(Promise.resolve()); | ||
|
||
getBlogPostsCollection().getTotalRecords({since: "ETAG"}); | ||
|
||
sinon.assert.calledWithMatch(client.execute, { | ||
method: "HEAD", | ||
path: "/buckets/blog/collections/posts/records?since=ETAG", | ||
}, {raw: true}); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
}); | ||
|
||
/** @test {Collection#getData} */ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So that means
since
is passed to_collOptions
and merged into the instance options. I don't think that it's a problem per se, but explicitely removing it may be nicer:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually, the
const { since, ...otherOptions } = options
instruction breaks the firefox build:https://travis-ci.org/Kinto/kinto-http.js/jobs/163077307#L959
Maybe this issue: browserify/module-deps#93
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sigh. Oh well.
Edit: just to be clear, that's because this is es7 and neither firefox and babel without specific transforms support this syntax.