Skip to content

Missing typing for sqlite3Worker1Promiser #155

Description

@realGriss

Type

Bug Report

Description

Hi,

I still get typing problems in the current version "3.51.2-build7". Trying to import with

import { sqlite3Worker1Promiser } from '@sqlite.org/sqlite-wasm'

gives me an error. This should be fixed with #54 Or am I missing something?

Activity

  1. jurerotar commented on Mar 12, 2026

    @jurerotar
    Contributor

    Hey, thank you for raising this! 😄

    I'll take a look and keep you updated!

  2. jurerotar commented on Mar 12, 2026

    @jurerotar
    Contributor

    Sorry about this! I've prepared a PR (#156) that should resolve this issue. I've also touched a bit on the types, specifically Worker1Promiser type is now exported, so you'll be able to use it for explicitly typing your variable, should you need to, and specific calls like config-get should now no longer require redundant second arguments 😄

  3. mmomtchev commented on Mar 12, 2026

    @mmomtchev
    Collaborator

    The Node.js version (dist/node.mjs) does not export it. I think this is the problem.

  4. tomayac commented on Mar 13, 2026

    @tomayac
    Collaborator

    Fixed by #156.

  5. jurerotar commented on Mar 16, 2026

    @jurerotar
    Contributor

    @realGriss, new release was just published, please let me know if the issue is solved! 😄

  6. realGriss commented on Mar 16, 2026

    @realGriss
    Author

    Types seems to work fine now. Thanks for the quick update.

    The only problem I'm running into is that I get a error with the current example:

    import {
      sqlite3Worker1Promiser,
      type Worker1Promiser,
    } from '@sqlite.org/sqlite-wasm';
    
    const log = console.log;
    const error = console.error;
    
    const initializeSQLite = async () => {
      try {
        log('Loading and initializing SQLite3 module...');
    
        const promiser = await new Promise<Worker1Promiser>((resolve) => {
          sqlite3Worker1Promiser({
            onready: resolve,
          });
        });
    
        log('Done initializing. Running demo...');
    
        const configResponse = await promiser('config-get');
        log('Running SQLite3 version', configResponse.result.version.libVersion);
    
        const openResponse = await promiser('open', {
          filename: 'file:mydb.sqlite3?vfs=opfs',
        });
        const { dbId } = openResponse;
        log(
          'OPFS is available, created persisted database at',
          openResponse.result.filename.replace(/^file:(.*?)\?vfs=opfs$/, '$1'),
        );
        // Your SQLite code here.
      } catch (err) {
        if (!(err instanceof Error)) {
          err = new Error(err.result.message);
        }
        error(err.name, err.message);
      }
    };
    
    await initializeSQLite();
    

    TypeError: Cannot create property 'dbId' on string 'config-get'

    Not sure if I'm doing something wrong here or this is a bug.

    Edit:
    It works if I use it like this:

    promiser('config-get', {});

  7. jurerotar commented on Mar 16, 2026

    @jurerotar
    Contributor

    Not sure if I'm doing something wrong here or this is a bug

    This is on me, being overzealous with the type improvements. Promiser API makes an explicit check for amount of parameters and assigns properties based on it. I missed that, sorry!

    I don't want to bother tomayac with preparing yet another build, so I'll just prepare a PR that updates the example and makes sure the types require all required params from now on 😄

  8. solodeveloping commented on Apr 14, 2026

    @solodeveloping

    The first example in the doc is still not working for me, I went back to using the example types in one of the threads.

    I get this in vscode: "Type '(value: any) => void' is not assignable to type 'OnreadyFunction'.
    Target signature provides too few arguments. Expected 1 or more, but got 0."

    And then the other methods are not typed either 😥

  9. jurerotar commented on Apr 14, 2026

    @jurerotar
    Contributor

    Thank you for raising the issue, I have the fix ready! 😄

    @tomayac, should we update the README promiser example to v2 style (using promises instead of callbacks)? It's a bit cleaner imo 😄

    const initializeSQLite = async () => {
      try {
        console.log('Loading and initializing SQLite3 module (v2 promise style)...');
    
        const promiser = await sqlite3Worker1Promiser.v2();
    
        console.log('Done initializing (v2 promise style). Running demo...');
    
        const configResponse = await promiser('config-get', {});
        console.log('Running SQLite3 version', configResponse.result.version.libVersion);
    
        const openResponse = await promiser('open', {
          filename: 'file:mydb-v2.sqlite3?vfs=opfs',
        });
        console.log(
          'OPFS is available, created persisted database at',
          openResponse.result.filename.replace(/^file:(.*?)\?vfs=opfs$/, '$1'),
        );
      } catch (err: any) {
        if (!(err instanceof Error)) {
          err = new Error(err.result.message || 'Unknown error');
        }
        console.error(err.name, err.message);
      }
    };
  10. tomayac commented on Apr 14, 2026

    @tomayac
    Collaborator

    I'd happily merge a quick PR that does that, yes.

  11. jurerotar commented on Apr 14, 2026

    @jurerotar
    Contributor

    I opened a PR here: #160

    I tried both v1 and v2 api versions and types seemed to work fine. Hopefully I didn't miss anything 😄

  12. solodeveloping commented on Apr 14, 2026

    @solodeveloping

    It's strange, in the current version, I have an error indicating that the v2 is not a function, and the default version seem to be the v2 when debugging the code.

    Is it normal?

  13. jurerotar commented on Apr 14, 2026

    @jurerotar
    Contributor

    It's strange, in the current version, I have an error indicating that the v2 is not a function

    Current version is incorrect. This PR should resolve this, see here: https://github.com/sqlite/sqlite-wasm/pull/160/changes#diff-619cc2239a7eb4ef05041767e6ab0e4fb069e98ee9d2c83c2d8e1865c475e141

    @tomayac, could I ask for a new release, please? 😄

  14. tomayac commented on Apr 14, 2026

    @tomayac
    Collaborator
  15. 2 remaining items

  16. sgbeal commented on Apr 15, 2026

    @sgbeal
    Collaborator

    As of today, worker1Promiser API is considered deprecated and will no longer be supported from our side. Next release will include the @deprecated tags to the types as well, but we already removed an example usage of this API, and added a deprecation notice to the README.

    Just to stress, though: upstream promises to not remove Worker1 for the life of the project. It will be maintained insofar as needed to keep older code working, so will get any necessary bug fixes but no new capabilities. That is: it's safe to continue using it, but... seriously, it's a toy and should not be used for anything but "hello, world" apps.

  17. solodeveloping commented on Apr 15, 2026

    @solodeveloping

    Is there an intention to provide more examples of such implementation in this project or to provide an extended library implementing this?

    Or should it be done elsewhere, like in another project?

  18. jurerotar commented on Apr 15, 2026

    @jurerotar
    Contributor

    Is there an intention to provide more examples of such implementation in this project or to provide an extended library implementing this?

    I'd be happy to provide more examples, but are the ones in /demo not descriptive enough?

  19. solodeveloping commented on Apr 15, 2026

    @solodeveloping

    I mean, it's sufficient, to be fair it does not do much that I could have figured by myself 😊 Even though it's not TS

    I suppose that this is not the place for a "real" library?

    I will change my code, hopefully I won't encounter too many problems 😊

  20. jurerotar commented on Apr 15, 2026

    @jurerotar
    Contributor

    @solodeveloping, ask and you shall receive 😄

    I've opened a PR which modernized the demos a tiny bit. Please let me know if this is what you had in mind 😄

  21. solodeveloping commented on Apr 17, 2026

    @solodeveloping

    Sorry, I missed the notification somehow.

    It does look better.

    I think there is an error in the main doc btw, maybe

    "new sqlite3.oo1.DB('/mydb.sqlite3', 'ct');" => this is possible only if you have setup a pool no? The other mods seem to require that filename be a special value (":memory:" for instance)

    https://sqlite.org/wasm/doc/trunk/api-oo1.md

    It's a bit unclear though

  22. sgbeal commented on Apr 17, 2026

    @sgbeal
    Collaborator

    "new sqlite3.oo1.DB('/mydb.sqlite3', 'ct');" => this is possible only if you have setup a pool no?

    That's legal as-is, but the db is transient, stored in the Emscripten-emulated virtual filesystem. This API has no connection pool. "c" means "create if it doesn't exist" and "t" means "enable the default logging tracer".

    It's a bit unclear though

    Functionally speaking, in the Emscripten virtual filesystem, there's almost no functional difference between /foo.db and :memory: because both are transient. The former has a persistent name for the life of the page, though, addressable via multiple connections, or closable/re-openable by a single connection.

  23. solodeveloping commented on Apr 17, 2026

    @solodeveloping

    Okay, thank you 😊

  24. solodeveloping commented on Apr 17, 2026

    @solodeveloping

    What are the differences between the new method and the Worker1 exactly?

    If I do a new web project, I can run some code, same code I can't run from my web extension.

    And the old way still works in my extension too.

    This gets blocked with the new method:

    Image

    And it does not in a new project, like I said.

  25. solodeveloping commented on Apr 17, 2026

    @solodeveloping

    Okay, found it:

    I assumed there was no reason for it to fail, and assumed there is a difference:

    // creates a bug, orinal version
    const W = new Worker(new URL("sqlite3-opfs-async-proxy.js", import.meta.url));
    // working (like in the Worker1 code):
    const W = new Worker(new URL("sqlite3-opfs-async-proxy.js", import.meta.url), {
    	type: "module"
    });

    I have a new issue opened at SQLite so I'll add this there.

  26. sgbeal commented on Apr 17, 2026

    @sgbeal
    Collaborator

    // working (like in the Worker1 code):
    const W = new Worker(new URL("sqlite3-opfs-async-proxy.js", import.meta.url), {
    type: "module"
    });

    That JS file is not a module and it must not be loaded directly by any client code. It's an internal detail of the library, not a client-facing part, and will be loaded automatically during initialization of the library if the library detects that OPFS is available.

  27. solodeveloping commented on Apr 17, 2026

    @solodeveloping

    I'm not sure of what you mean, this is the code as it is in the library.

  28. sgbeal commented on Apr 17, 2026

    @sgbeal
    Collaborator

    I'm not sure of what you mean, this is the code as it is in the library.

    Then you're looking at an old version.

  29. solodeveloping commented on Apr 17, 2026

    @solodeveloping

    I'm on "@sqlite.org/sqlite-wasm": "3.51.2-build9", which is the last one on npm too

  30. solodeveloping commented on Apr 17, 2026

    @solodeveloping

    Yeah, this is the code I find here https://www.npmjs.com/package/@sqlite.org/sqlite-wasm?activeTab=code

    And it's the code I find here

    new Worker(new URL("sqlite3-opfs-async-proxy.js", import.meta.url));

    Which I assume becomes "index.mjs", which is the main script ""main": "./dist/index.mjs"," (in package.json)

    If there is a change, maybe it's in a dev branch?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions