techfort / LokiJS

javascript embeddable / in-memory database
http:/techfort.github.io/LokiJS
MIT License
6.74k stars 482 forks source link

Can you add typescript support? #907

Open masx200 opened 2 years ago

masx200 commented 2 years ago

Can you add typescript support?

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

jakobo commented 2 years ago

Out of curiosity, are there things @types/lokijs isn't covering? The only item I've really come across so far is the $exists operator which isn't exposed on the top level. It might be helpful to have a list of types that need fixing.

https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/lokijs/index.d.ts

Based on the type file history, it seems very receptive to PRs as well.

Losses commented 2 years ago

Unfortunately, the typing definition provided by @types missed some detail about many classes, marked a lot of things as any which make the definition less useful, and most important, not included the typing for all adapters.

jakobo commented 2 years ago

Based on the roadmap I don't think a TS migration is planned. We can either add our own .d.ts or PR against @types/lokijs. My suggestion is we improve the external types when we bump against rough edges since those already have tests in place and cover a lot of Loki's API surface area.

A quick list of changes for those who are really good at typings:


Additional Context:

  1. A ts fork of Loki was made (last updated 2020 and appears abandoned). Meanwhile, the Nozbe team did several IndexedDB improvements in 2021 and techfort sees to be merging PRs again.
  2. There are some Loki alternatives out there with TS support, but all seem to end up in a pile of abandoned software
  3. As a last resort, if you need a fully typed in-memory DB with query support, I'd recommend either typicode/lowdb or a combination of fake-indexeddb & Dexie. Not to be dismissive of the typing problems, but specifically because typing something as complex as Mongo / Mango style filtering operations is really difficult to add after-the-fact.
Losses commented 2 years ago

I spent 6 days fully reviewing most of Loki's code (~6000 lines), and finally came to the conclusion that perhaps we have to do some house-keeping work to modernize the project and improve the code quality.

In addition, the mongo-like query is not the most tough one, writing typing definition for the Transform API and the lens implantation ( getIn and deepProperty ) is even more desperate, I've did a lot of experiment about these API.

Maybe I should write a complete code review report but it's too late today, I think it will happen after I finished reading the last part of the source code.

BTW, actually there is another fork called loki-collections, but it is much different from original Loki.js