Disclaimer: I'm not committing to maintaining typings here (rather than DT) and it will not be a blocker for release. I just found them useful when implementing level-transcoder and also wanted to learn something new.
Start here. The main export is AbstractLevel<TFormat, KDefault = string, VDefault = string> with three generic type parameters:
TFormat: the type used by the implementation to store data; see level-transcoder for background
KDefault: the type of keys, if not overridden on individual methods
VDefault: the type of values, if not overridden.
Downstream, for example in memory-level (the replacement for memdown), the types will look like this (simplified):
For a consumer of such an implementation, usage in TypeScript then looks like this:
// Specify types of keys and values (any, in the case of json).
// The generic type parameters default to level<string, string>.
const db = new MemoryLevel<string, any>({ valueEncoding: 'json' })
// All relevant methods then use those types
await db.put('a', { x: 123 })
// Specify different types when overriding encoding per operation
await db.get<string, string>('a', { valueEncoding: 'utf8' })
// Though in some cases TypeScript can infer them
await db.get('a', { valueEncoding: db.valueEncoding('utf8') })
Which I believe to be a fair balance between DX and maintainable (simple) typings. I will push new code and typings to memory-level later; might make it easier to review if you have an actual database to play around with.
Disclaimer: I'm not committing to maintaining typings here (rather than DT) and it will not be a blocker for release. I just found them useful when implementing
level-transcoder
and also wanted to learn something new.Start here. The main export is
AbstractLevel<TFormat, KDefault = string, VDefault = string>
with three generic type parameters:TFormat
: the type used by the implementation to store data; seelevel-transcoder
for backgroundKDefault
: the type of keys, if not overridden on individual methodsVDefault
: the type of values, if not overridden.Downstream, for example in
memory-level
(the replacement formemdown
), the types will look like this (simplified):For a consumer of such an implementation, usage in TypeScript then looks like this:
Which I believe to be a fair balance between DX and maintainable (simple) typings. I will push new code and typings to
memory-level
later; might make it easier to review if you have an actual database to play around with.