orbitdb / orbit-db-types

Unofficial orbit-db typings!
MIT License
26 stars 36 forks source link

[fix] KeyValueStore should return string for put/set/del operations instead of void #33

Closed chrispanag closed 3 years ago

chrispanag commented 3 years ago

As per the documentation the put/set/del operations of the KeyValueStore, should return a string containing the multihash of the entry.

But, in this types package, those operations return void.

This pull request fixes those types.

chrispanag commented 3 years ago

@aphelionz sorry for pinging you.

Does this pull request make sense for you? :)

aphelionz commented 3 years ago

Does this pull request make sense for you? :)

Almost! :)

Looking at the implementation, it seems that set, put, and del all call orbit-db-store#_addOperation, which then calls p-queue#add, which returns Promise<TaskResultType>.

I'm not super familiar with TypeScript - is the right thing to do here somehow import the TaskResultType generic and use it in our types?

chrispanag commented 3 years ago

Does this pull request make sense for you? :)

Almost! :)

Looking at the implementation, it seems that set, put, and del all call orbit-db-store#_addOperation, which then calls p-queue#add, which returns Promise<TaskResultType>.

I'm not super familiar with TypeScript - is the right thing to do here somehow import the TaskResultType generic and use it in our types?

Actually not. Firstly, you can't import a generic type variable.

Secondly, the function's declaration is:

async add<TaskResultType>(fn: Task<TaskResultType>, options: Partial<EnqueueOptionsType> = {}): Promise<TaskResultType>

Which with type coercion would become:

async add<string>(fn: Task<string>, options: Partial<EnqueueOptionsType> = {}): Promise<string>

So the return type of the set, put and del will return Promise<string> which is exactly what we need to add to the types.

Thank you for taking the time to look into it! :)