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

Push down dynamic data in /lemgram_count response for easier typing #28

Open
arildm opened this issue Dec 12, 2024 · 0 comments
Open

Push down dynamic data in /lemgram_count response for easier typing #28

arildm opened this issue Dec 12, 2024 · 0 comments

Comments

@arildm
Copy link
Member

arildm commented Dec 12, 2024

/lemgram_count returns a mapping of lemgram strings to counts. The data is on the top level of the response, beside time and ERROR.

This is a little annoying to handle in TypeScript. For other API endpoints, the following code successfully identifies an error response:

if ("ERROR" in data) {
  throw new KorpBackendError(data.ERROR.type, data.ERROR.value)
}

But when using this for /lemgram_count, this is invalid, as TypeScript believes data.ERROR could be a number (as if "ERROR" was a lemgram in a successful response).

It can easily be worked around, but I would suggest pushing the counts mapping down under a member called counts or so, to separate the dynamic data from the predictable members:

{
  "counts": {
    "katt..nn.1": 5
  },
  "time": 0.123
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant