dynogels icon indicating copy to clipboard operation
dynogels copied to clipboard

Keep getting Error: Invalid schema content when I use define

Open steve-cuzzort opened this issue 5 years ago • 3 comments

I cannot make even the simplest of schemas without getting an invalid schema error.

Code to reproduce

Main.ts `

import dynogels = require("dynogels");
import { DynamoDB } from "aws-sdk";
import * as Joi from "joi";
// AWS Configs
//dynogels.AWS.config.loadFromPath('credentials.json');
dynogels.AWS.config.update({ region: "us-east-1" });

// Define a Model
const Account = dynogels.define('Account', {
    hashKey: 'email',

    // add the timestamp attributes (updatedAt, createdAt)
    timestamps: true,

    schema: {
        email: Joi.string().email(),
        name: Joi.string(),
        age: Joi.number(),
        roles: dynogels.types.stringSet(),
        settings: {
            nickname: Joi.string(),
            acceptedTerms: Joi.boolean().default(false),
            test: {
                evan: Joi.string()
            }
        }
    }
});

`

package.json { "name": "stackoverflowpost", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC", "dependencies": { "@hapi/hoek": "^9.0.4", "@types/dynogels": "^9.0.3", "@types/joi": "^14.3.4", "aws-sdk": "^2.735.0", "dynogels": "9.10.0", "joi": "^17.2.0", "typescript": "^3.9.7" } }

When I run

ts-node main.ts

I get the following error

/Users/stephencuzzort/Projects/StackOverflowPost/node_modules/hoek/lib/index.js:740 throw new Error(msgs.join(' ') || 'Unknown error'); ^ Error: Invalid schema content: at Object.exports.assert (/Users/stephencuzzort/Projects/StackOverflowPost/node_modules/hoek/lib/index.js:740:11) at Object.exports.schema (/Users/stephencuzzort/Projects/StackOverflowPost/node_modules/dynogels/node_modules/joi/lib/cast.js:67:10) at internals.Object.keys (/Users/stephencuzzort/Projects/StackOverflowPost/node_modules/dynogels/node_modules/joi/lib/types/object/index.js:309:35) at Object.exports.schema (/Users/stephencuzzort/Projects/StackOverflowPost/node_modules/dynogels/node_modules/joi/lib/cast.js:48:33) at internals.Object.keys (/Users/stephencuzzort/Projects/StackOverflowPost/node_modules/dynogels/node_modules/joi/lib/types/object/index.js:309:35) at Object.exports.schema (/Users/stephencuzzort/Projects/StackOverflowPost/node_modules/dynogels/node_modules/joi/lib/cast.js:48:33) at internals.Object.keys (/Users/stephencuzzort/Projects/StackOverflowPost/node_modules/dynogels/node_modules/joi/lib/types/object/index.js:309:35) at Joi.validate (/Users/stephencuzzort/Projects/StackOverflowPost/node_modules/dynogels/lib/schema.js:107:71) at internals.Object._validateWithOptions (/Users/stephencuzzort/Projects/StackOverflowPost/node_modules/dynogels/node_modules/joi/lib/types/any/index.js:654:20) at module.exports.internals.Any.root.validate (/Users/stephencuzzort/Projects/StackOverflowPost/node_modules/dynogels/node_modules/joi/lib/index.js:121:23)

steve-cuzzort avatar Aug 18 '20 02:08 steve-cuzzort

It looks like this is a conflict between the version of Joi used by dynogels and the version your application is using.

@clarkie We should probably make Joi a peer dependency.

cdhowie avatar Aug 20 '20 00:08 cdhowie

That was it.

import * as Joi from "dynogels/node_modules/joi";

fixed it.

steve-cuzzort avatar Aug 20 '20 01:08 steve-cuzzort

Stumbled into this thread when investigating a Joi issue.

We were using @hapi/Joi "^15.1.1" across an application and tried to upgrade to 17.1.1 to fix a schema issue and thats when it all started to fall apart when the db libraries that use dynogels were pulled in and we started to see exceptions being thrown.

Then attempted to move to Joi since hapi was being deprecated anyways and still saw exceptions.

Have tried import * as Joi from "dynogels/node_modules/joi"; as per above suggestion but now we get

"errorType": "TypeError", "errorMessage": "Cannot set property '_internals' of undefined",

when the db layer that uses dynogels is imported

Not feeling the Joi right now ;)

Will keep trying a few things to see if we can massage a solution into place

e-plause avatar Oct 22 '20 22:10 e-plause