node.jssqliteknex.jsfeathersjsobjection.js

FeathersJS cannot create user with ObjectionJS and SQLite


I am experimenting with FeathersJS. To do so, I generated a new feathers app $ feathers g app with the following configuration:

? Do you want to use JavaScript or TypeScript? JavaScript
? Project name test
? Description
? What folder should the source files live in? src
? Which package manager are you using (has to be installed globally)? npm
? What type of API are you making? REST, Realtime via Socket.io
? Which testing framework do you prefer? Mocha + assert
? This app uses authentication Yes
? Which coding style do you want to use? ESLint
? What authentication strategies do you want to use? (See API docs for all 180+ supported oAuth providers) Username + Password (Local)
? What is the name of the user (entity) service? users
? What kind of service is it? Objection
? Which database are you connecting to? SQLite
? What is the database connection string? sqlite://test.sqlite

When I run the test suite $ npm run tests, it throws an error ERR GeneralError: strict mode: unknown keyword: "0"

So far, I understood that this error is raised somewhere in AJV that is used by Knex and that it is somehow related to schema validation. I also tried posting to http://localhost:3030/users in order to create a users but I get the same error.

I ran the same experiment with apps configured to use Knex + SQLite and Sequalize + SQLite. Those setups let me create new users.

Does anyone have any idea where this error may come from and how to solve it?


Solution

  • Found the problem. The feathers generator creates the following jsonSchema within the ObjectionJS model:

     static get jsonSchema() {
        return {
          type: 'object',
          required: ['password'],
    
          properties: {
          
            email: { type: ['string', 'null'] },
            password: 'string',
          
          }
        };
      }
    

    which features a wrong syntax for the password property. It needs to be password: { type: 'string' } to work.