Skip to content

API filter by build tool #1300

Closed
Closed

Description

@lpil

Hello friends!

The Gleam packages website maintains a copy of all the packages with the gleam build tool, which it gets by traversing the Hex API from newest to oldest until it finds new releases with that tool.

Would you be open to adding a filtering option for the build tools used? This would save both Hex and the Gleam packages site some work of sending the non-Gleam releases JSON over the network.

If you're open to this and have a particular design in mind I'm sure someone in the Gleam world could contribute an implementation.

Thank you,
Louis

Activity

  1. wojtekmach commented on Apr 8, 2025

    @wojtekmach
    Member

    Hey @lpil, apologies for delay. Yes, this sounds good.

    In fact we can do that today already with a little bit of extra work from your end (that we're OK to lessen, explained next).

    Since #351 we can attach arbitrary "extra" metadata to packages. So we can have this:

    # mix.exs
    
      defp package() do
        [
          description: "Lorem ipsum",
          licenses: ["Apache-2.0"],
          links: %{},
          extra: %{gleam: "true"}
        ]
      end

    (Note "true" currently needs to be a string, an atom true won't do.)

    And then we can search on the website/API using this filter extra:gleam,true.

    Image
    $ curl -fsS "http://localhost:4000/api/packages?search=extra:gleam,true" | jq '.[].name'
    "hexpm_dev_foo"
    

    Instead of %{gleam: "true"} you can do anything today, say %{language: "gleam"}. You could even store whether given package has, say, JS target, totally up to you. (It could be %{gleam_targets: ["erlang", "javascript"]} and then to find packages that have both, search query would be: extra:gleam_targets,[erlang] extra:gleam_targets,[javascript]


    If this would to work out of the box, do you have any preferences how it should look like?

    We could make build_tools:gleam, build_tools:gleam,mix etc work.

    In terms of implementation, this should do it:

    iex> q = from(r in Hexpm.Repository.Release, where: fragment("jsonb_exists_all(?, ?)", r.meta["build_tools"], ["gleam", "mix"]))
    iex> Hexpm.Repo.all(q)

    If it were to be out of the box we're not sure whether we should segment based on build tool or language, in Gleam's case it's kind of one and the same of course, so curious if you have any feedback about that point.

  2. lpil commented on Apr 9, 2025

    @lpil
    ContributorAuthor

    Brilliant, thank you!

    I'd like it to work for all the package releases that have already been published, so I think searching by the build tool would be best, as the extra field is not yet populated.

    I don't have any particular preferences for the query syntax, what you've presented there looks great to me.

    If it were to be out of the box we're not sure whether we should segment based on build tool or language, in Gleam's case it's kind of one and the same of course, so curious if you have any feedback about that point.

    I didn't know there was a field for language! How are the languages of a package determined?

  3. wojtekmach commented on Apr 9, 2025

    @wojtekmach
    Member

    Sorry for confusion, that's the thing, there isn't a field for the language at the moment.

  4. lpil commented on Apr 9, 2025

    @lpil
    ContributorAuthor

    Oh right!

    The Gleam build tool can compile 3 languages and with plugins Mix and Rebar can compile any number of languages, so maybe it's easier to go by build tool.

  5. wojtekmach commented on Apr 10, 2025

    @wojtekmach
    Member

    Yes, let's roll with filtering per build_tool, I suppose we can always add filtering per language down the road if there would be good use cases for that. WDYT @ericmj?

    In terms of implementation, one needs to add a

    defp search_param("build_tool", search, query) do
    

    like

    defp search_param("extra", search, query) do

  6. lpil commented on Apr 21, 2025

    @lpil
    ContributorAuthor

    Excellent, sounds great! I'll see if anyone on the Gleam side would be able to make a PR for this.

  7. added a commit that references this issue on May 6, 2025
    ad9f838
  8. PragTob commented on May 6, 2025

    @PragTob
    Contributor

    I took a stab at this in #1304 :)

  9. added a commit that references this issue on May 8, 2025
    0b8499c
  10. added a commit that references this issue on Oct 21, 2025
    39e2268
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions