Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite or replace polymorphic functions #1754

Open
dstaley opened this issue Aug 31, 2019 · 1 comment
Open

Rewrite or replace polymorphic functions #1754

dstaley opened this issue Aug 31, 2019 · 1 comment
Assignees

Comments

@dstaley
Copy link
Member

dstaley commented Aug 31, 2019

There are a handful of functions that change their return type based on supplied parameters. This requires us to manually cast the function to the expected type, which isn't ideal. We should replace these functions with versions that either only return one type, or with multiple functions that each return only one type.

Polymorphic functions:

  1. KintoClientBase.execute - Returns HttpResponse<T> if options.raw is true, otherwise T. Can likely be modified to always return HttpResponse<T>.
  2. KintoClientBase.batch - Returns AggregateResponse if options.aggregate is true, otherwise OperationResponse[]. Could possibly just ask the caller to call aggregate on the return value manually.
  3. Collection.listRecords - Returns a snapshot if options.at is provided, otherwise PaginationResult. Turns out this one actually can return the same type regardless of the input.
@dstaley
Copy link
Member Author

dstaley commented Feb 26, 2020

Hopefully whatever solution comes out of rewriting batch would solve this monstrosity:

const res = ((await api.batch((batch: KintoClientBase) => {
  batch.bucket("custom").listCollections();
})) as unknown) as OperationResponse<KintoObject[]>[];
res[0].body.data.map(r => r.id).should.deep.equal(["c4", "c3", "c2", "c1"]);

@dstaley dstaley transferred this issue from Kinto/kinto-http.js Apr 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant