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

Prototype-based selectors and predicates #213

Open
0x009922 opened this issue Feb 16, 2025 · 0 comments
Open

Prototype-based selectors and predicates #213

0x009922 opened this issue Feb 16, 2025 · 0 comments

Comments

@0x009922
Copy link
Contributor

Current implementation

In the current design, the predicates and selectors are constructed directly, as all other data model types:

const accounts: types.Account[] = await client.find
  .accounts({
    predicate: types.CompoundPredicate.Atom(
      types.AccountProjectionPredicate.Id.Domain.Name.Atom.EndsWith('land')
    )
  })
  .executeAll()

 const items: [types.Hash, types.AccountId][] = await client.find
   .transactions({
     selector: [
       types.CommittedTransactionProjectionSelector.BlockHash.Atom,
       types.CommittedTransactionProjectionSelector.Value.Authority.Atom,
     ],
   })
   .executeAll()

This is somewhat unintuitive and verbose, and is different from how these work in Rust:

TODO: a snippet in Rust with QueryBuilder

Desired solution

The desired way is to adopt a similarly-looking strategy from Rust, i.e. by using callbacks with "prototypes" of the entities, as if we are actually accessing fields on the final structures:

const accounts: types.Account[] = await client.find
  .accounts({
    filterWith: (account) => account.id.domain.name.endsWith('land')
  })
  .executeAll()

const items: [types.Hash, types.AccountId][] = await client.find
 .transactions({
   selectWith: (tx) => [tx.blockHash, tx.value.authority],
 })
 .executeAll()
@0x009922 0x009922 changed the title Ergonomic selectors and predicates Prototype-based selectors and predicates Feb 17, 2025
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