lucid-mongo icon indicating copy to clipboard operation
lucid-mongo copied to clipboard

Model hooks won't work when library used stand-alone

Open cybercats-team opened this issue 6 years ago • 1 comments

Stack: TypeError: Cannot read property 'resolveFunc' of undefined at Hooks.exec (/Users/alexserdukov/Documents/Projects/Mobilunity/sites/mytransics/Tx-SystemAlarmsApi/node_modules/lucid-mongo/src/LucidMongo/Hooks/index.js:166:55)

The reason is that there are no working stub for forDir() method:

class Resolver {
  forDir () {
  }
}

I added in my project some workarounds for callbacks / arrow functions can be supported. Hope it helps for someone faced this issue, and I hope this workaround (or another solution) could be added to next releases.

const { resolver } = require("lucid-mongo/lib/iocResolver");

resolver.forDir = () => ({
  resolveFunc: handler => {
    if ('string' === (typeof handler)) {
       throw new Error('References handlers aren\'t supported in stand-alone mode');
    } else if ('function' !== (typeof handler)) {
       throw new Error('Invalid handler passed');
    }

    return {method: handler};
  }
});

cybercats-team avatar Jun 27 '18 09:06 cybercats-team

Had the same issue, the workaround works. I think it would be great to make the standalone mode solid and bug-free. This ORM is much better compare to others I tested (with support for both relational dbs and Mongo).

martinlevesque avatar Feb 19 '19 21:02 martinlevesque