LokiJS icon indicating copy to clipboard operation
LokiJS copied to clipboard

Can you add typescript support?

Open masx200 opened this issue 2 years ago • 5 comments

Can you add typescript support?

masx200 avatar Feb 27 '22 08:02 masx200

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.

stale[bot] avatar Apr 28 '22 11:04 stale[bot]

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.

jakobo avatar Sep 27 '22 02:09 jakobo

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.

Losses avatar Oct 03 '22 13:10 Losses

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:

  • address any usage. Where possible, any should become unknown
  • add the $exists operator ref
  • add missing adapters and adapter methods
    • LokiFsStructuredAdapter
    • LokiIndexedAdapter
    • LokiPartitioningAdapter official docs do not mention a lot of methods in the types

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.

jakobo avatar Oct 03 '22 20:10 jakobo

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

Losses avatar Oct 06 '22 14:10 Losses