sqlite-wasm icon indicating copy to clipboard operation
sqlite-wasm copied to clipboard

Add `sqlite3Worker1Promiser` type declarations

Open tomayac opened this issue 2 years ago • 7 comments

Fixes #53

tomayac avatar Nov 27 '23 09:11 tomayac

This is going to need lots of overloads:

A Promiser object is a function with two call signatures:

   ( messageType, messageArguments ) is equivalent to:
   ( {type: messageType, args: type-specific value} )

where the type is always a string and the args value is message-type specific. It always returns a Promise object which resolves to an object:

{
  type: messageType,
  result: type-specific result value,
  ... possibly other metadata ...
}

https://sqlite.org/wasm/doc/tip/api-worker1.md#promiser

jbaiter avatar Nov 27 '23 21:11 jbaiter

Hi, I wanted to let you know that I am currently working on writing the types. I expect to be in a position to share my work with you in the next few days.

GabrielDelepine avatar Feb 11 '24 17:02 GabrielDelepine

Hey, I just added some partial types to a project recently. They are not comprehensive by any means, but maybe they can serve to get started or to get some ideas: https://github.com/moodlehq/moodleapp/blob/main/src/types/sqlite-wasm.d.ts

NoelDeMartin avatar Feb 15 '24 12:02 NoelDeMartin

Hi, Still working on it, fine-tuning messageId to unlock its full potential

GabrielDelepine avatar Feb 26 '24 14:02 GabrielDelepine

Note that the messageId is an internal-use property used for dispatching messages between the worker and callbacks. It is hypothetically conceivable for clients to tinker with but no actual use for that comes to mind. FWIW, IMO messageId should be flagged as an opaque type of no interest to clients.

sgbeal avatar Feb 26 '24 17:02 sgbeal

Hi, I made a PR to merge with this adding most of the Sqlite3Worker1Promiser related types https://github.com/sqlite/sqlite-wasm/pull/76. Still have a few things left to do mainly with PromiserMethods, but would appreciate a second look from anyone interested

sameoldlab avatar May 28 '24 08:05 sameoldlab

Also copying over my progress comment avoid splitting overall progress discussion:

Progress:

  • [ ] Mostly done with Sqlite3Worker1PromiserConfig. Not sure what goes in for the args of generateMessageId
  • [ ] Need clearer documentation for Promiser Method open's filename and vfs
  • [ ] exec needs to add a full list of arguments, js eqivalent for sql VALUE value used in row and bind
  • [ ] There is additional metadata returned by Promiser. Described as "// possibly other metadata ..." on sqlite docs. Not sure how stable these are / if they should be documented here.
  • [ ] Need to add type for Promiser response error stack trace array

As the methods are very similar to worker1, I'm hoping I can reduce what is specified here and reuse the existing types where possible.

sameoldlab avatar May 28 '24 08:05 sameoldlab