-
-
Notifications
You must be signed in to change notification settings - Fork 297
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
I am unable to specify a data type for my index, and that compromises the type safety #456
Comments
Hi @FlushBG, we're working on it. We'll open a PR to fix it ASAP. |
/bounty $150 |
💎 $150 bounty created by micheleriva
|
/attempt #456 Options |
@micheleriva Some questions:
|
Hi @H4ad, let me answer your points:
Yes. Properties that are not defined in the schema are not searchable, but they can be inserted.
They should be required. @allevo any thoughts? Should we make them optional?
Since we don't know what the extra properties look like, we can't determine their type. We can't also infer them as they could change from document to document.
I'd let @allevo to answer this one |
@H4ad I think inferring types from the schema is good. But we could also create a generic type like: import { search } from '@orama/orama'
type MyDoc = {
id: 'string',
title: 'string',
foo?: 'number',
bar?: 'boolean'
}
const results = search<MyDoc>(db, {
term: ''
}) Internally, Orama could merge the |
@micheleriva For the insert, I leave all the properties optional but for most cases I allow the user to override the return object if it matches with the schema. Some preview of the current state: Now I'm fixing a bunch of other issues with types, I will try to create a PR on the weekend for this feature. /attempt #456 Options |
Note: The user @evonloch is already attempting to complete issue #456 and claim the bounty. If you attempt to complete the same issue, there is a chance that @evonloch will complete the issue first, and be awarded the bounty. We recommend discussing with @evonloch and potentially collaborating on the same solution versus creating an alternate solution. |
Hey @evonloch, what's your progress on this? I'm really interested in this issue. |
@H4ad I am still working in it. |
💡 @H4ad submitted a pull request that claims the bounty. You can visit your org dashboard to reward. |
@H4ad: Your claim has been rewarded! 👉 Complete your Algora onboarding to collect the bounty. |
🎉🎈 @H4ad has been awarded $150! 🎈🎊 |
Describe the bug
I am using Orama search in a NestJS project. The use case is as follows:
The issue I'm facing is that I can't find a way to specify a type for the objects this index will be storing. Since the schema is only used to specify the searchable fields, I feel there should be a way to tell the index the full data schema that it will be holding. Currently, the search function returns the hits and the documents that were hit, but the return type is Document and it isn't generic. This causes some issues for other services (e.g. UserService), which are required to return an array of users - User[].
The current workaround is to either:
cast the document to unknown, and then to the type you need
const user = document as unknown as User
manually map each property you need:
To Reproduce
Steps to reproduce the behavior:
Expected behavior
For the sake of type safety, I would expect to be able to specify the form of data my index will be holding, and avoid casting and / or mapping. A good approach would be to make all Orama methods generic, or at least the create method - so you can pass the type of your index when making it.
Example given:
Additional context
The version of Orama I am facing this issue on is 1.1.1
The text was updated successfully, but these errors were encountered: