JuanCouste / overpass-ql-ts

Overpass QL query builder abstraction with typing
MIT License
5 stars 1 forks source link

Concise tag filter #20

Open multimeric opened 3 months ago

multimeric commented 3 months ago

I want to represent way[highway], which is a nice simple expression in Overpass QL.

As far as I can tell, the simplest way to represent the above query is this:

api.execJson(s => s.way.byTags(builder => ({
    highway: builder.exists()
})))

In terms of line number it's not an issue, but I find the amount of nested functions makes it hard to parse:

My first suggestion is if you could extend the object syntax ("OverpassQueryTagFitlerObject") to allow booleans to check for existence:

api.execJson(s => s.way.byTags({
    highway: true
}))

Another alternative might be to just make the builder object a constant:

import { FetchOverpassApi, OverpassOutputVerbosity, OverpassFormat, OverpassState, TagBuilder } from "overpass-ql-ts";

api.execJson(s => s.way.byTags({
    highway: TagBuilder.exists()
}))
JuanCouste commented 3 months ago

The boolean option seems like a good addition, in the meantime, you can import OverpassTagFilterBuilderImp or OverpassExistsTagFilterHelper and instance it yourself:

const exists = new OverpassExistsTagFilterHelper(false); // negated: false
const not_exists = new OverpassExistsTagFilterHelper(true);  // negated: true