I am working on a Typescript library (to be used by many users within my org, possibly open-sourced) which provides access to some remote storage. I am contemplating between several variants for the main methods. Let's take the "query" method as an example. Here are several alternatives for its signature:
// alternative (a) - pass a single object (named arguments)
const items[] = await client.query({
expression: "a1 = :v1",
filter: "a2 > :v2"
values: {v1: 'foo', v2: 'bar'},
timeoutMs: 100,
numItems: 3,
consistency: "STRONG"})
// alternative (b) - pass multiple values (positional arguments)
const items[] = await client.query("a1 = :v1", "a2 > :v2",
{v1: 'foo', v2: 'bar'}, 100, 3, "STRONG")
// alternative (c), split to to two methods,
// pass positional arguments
const items[] = client.query("a1 = :v1", "a2 > :v2",
{v1: 'foo', v2: 'bar'})
.fetch(100, 3, "STRONG")
// alternative (d) - split to two methods
// pass positional arguments to the former, named to the latter
const items[] = client.query("a1 = :v1", "a2 > :v2",
{v1: 'foo', v2: 'bar'})
.fetch({timeoutMs: 100, numItems: 3, consistency: "STRONG"})
// alternative (e) - split to two methods,
// pass positional arguments to both
const items[] = client.query({
expression: "a1 = :v1",
filter: "a2 > :v2"
values: {v1: 'foo', v2: 'bar'})
.fetch({timeoutMs: 100, numItems: 3, consistency: "STRONG"})
(there probably other alternatives one can think of...)
Contemplation #1
In order to perform a query should the call site call a single method (query() - as shown in (a), (b)) or two methods (query() followed by fetch() - as shown in (c), (d), (e)).
calling a single method is conceptually simpler. OTOH, splitting it to two makes it easy for users of the library to perform "chunk processing": read 10 items, inspect them, read 20 more, inspect them, read some more, etc.
Contemplation #2
named vs. positional? (in either the query() or fetch() methods)
named arguments are more explicit and make it easier to pass any subset of the optional arguments. On the other hand, the call sites are more verbose which is often a major deterring factor.