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

implement #138 since option for collection.getTotalRecords #142

Closed
wants to merge 3 commits into from

Conversation

elelay
Copy link
Contributor

@elelay elelay commented Sep 16, 2016

getTotalRecords(options) has been released already, so this is a breaking API change but not many have jumped on it I hope...

* @param {Object} [options={}] The options object.
* @param {Object} [options.headers] The headers object option.
* @return {Promise<Number, Error>}
*/
getTotalRecords(options={}) {
getTotalRecords(since, options={}) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should follow what was done in listRecords() : make since an option. Plus, it wouldn't break the API!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

method: "HEAD",
path: "/buckets/blog/collections/posts/records?since=ETAG",
}, {raw: true});
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

return this.client.execute({
method: "HEAD",
path: endpoint("record", this.bucket.name, this.name),
path: path,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: just path is enough.

Copy link
Contributor

@n1k0 n1k0 Sep 27, 2016

Choose a reason for hiding this comment

The 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})

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've used path directly. Is there something else to do?

Copy link
Contributor

Choose a reason for hiding this comment

The 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})

* @return {Promise<Number, Error>}
*/
getTotalRecords(options={}) {
const { headers } = this._collOptions(options);
let path = endpoint("record", this.bucket.name, this.name);
if(options.since){
path += "?since="+options.since;
Copy link
Contributor

@n1k0 n1k0 Sep 27, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be nice to reuse the utils.qsify function here.

Also nit: space around operand

* @return {Promise<Number, Error>}
*/
getTotalRecords(options={}) {
const { headers } = this._collOptions(options);
let path = endpoint("record", this.bucket.name, this.name);
if(options.since){
Copy link
Contributor

@n1k0 n1k0 Sep 27, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: space after if and before {

@@ -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);
Copy link
Contributor

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:

getTotalRecords(options={}) {
  const { since, ...otherOptions } = options;
  const { headers } = this._collOptions(otherOptions);
  let path = endpoint("record", this.bucket.name, this.name);
  if (since) {
    path += "?since="+options.since;
  }

Copy link
Contributor Author

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

Copy link
Contributor

@n1k0 n1k0 Sep 27, 2016

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.

@leplatrem leplatrem closed this Apr 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants