voxgig / seneca-promisify

Seneca plugin that adds a promise-based API for the core methods.
MIT License
2 stars 3 forks source link

When used with seneca-entity, await-ing on seneca.make$ is not awaited on #18

Open lilsweetcaligula opened 1 year ago

lilsweetcaligula commented 1 year ago

The following can be reproduced by using many stores, but in this example we're using seneca-knex-store against a postgres instance. Before you can run the code, create the racers table:

CREATE TABLE racers (
  id VARCHAR(36) NOT NULL,
  username VARCHAR(255) NOT NULL,
  favorite_car VARCHAR(255) NOT NULL,

  PRIMARY KEY (id),
  UNIQUE(username)
);
        const configDB = {
          // some code here
        }

    const seneca = Seneca()
        .test()
        .use('promisify')
        .use('entity', { mem_store: false })
        .use('seneca-knex-store', configDB)

    await seneca.ready()

    await seneca.make$('racers')
        .save$({
            username: 'Jose',
            favorite_car: 'Ferrari'
        })

    throw new Error('Oops!')

    await seneca.make$('racers')
        .save$({
            username: 'Leo',
            favorite_car: 'Lamborghini'
        })

After running the code, inspection of the database with psql shows that no racers were created, which means the first call to .save$ was not properly awaited on.

Replacing seneca.make$ with seneca.entity does fix this issue, but it would be nice (and less surprising) if seneca.make$ worked as well.

rjrodger commented 1 year ago

ah - sadly this can't be fixed as seneca.make$ must remain backward compatible and hence does not return Promise enabled entities