zazuko / query-rdf-data-cube

Explore or query RDF Data Cubes with a JavaScript API, without writing SPARQL.
https://zazuko.github.io/query-rdf-data-cube/
9 stars 2 forks source link

Better types for query.execute() #39

Closed jstcki closed 4 years ago

jstcki commented 4 years ago

Currently, query.execute() has the return type Promise<any[]> which should probably be something like Promise<Record<string, NamedNode | Literal>[]> (or use Term instead of NamedNode | Literal?)?

The string key could also be made generic, so one could do cube.query<"foo" | "bar">().execute() => Promise<Record<"foo" | "bar", NamedNode | Literal>>, and the SelectsObj and SelectsArr arguments could also use that. But maybe that goes too far …

vhf commented 4 years ago

Good idea, thanks!

I won't be able to work on this before mid-November but I added it to my plans

jstcki commented 4 years ago

Great, thanks! I could also make a PR for it (but I assume you won't merge/release that in the meantime as well).

vhf commented 4 years ago

PRs are welcome obviously but correct: I won't merge in the meantime :) (I'll be off for two weeks starting from this afternoon)

jstcki commented 4 years ago

OK! Enjoy your vacation! 🌴

jstcki commented 4 years ago

I think I got this wrong: from looking at the actual query results, a (more) correct type would be

Promise<
  Array<
    Record<
      string,
      {
        value: Literal | NamedNode;
        label?: Literal;
      }
    >
  >
>;
vhf commented 4 years ago

I checked, this looks correct indeed. Thanks!

d2dba1c / 0.4.1