Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep getting Error: Invalid schema content when I use define #191

Open
steve-cuzzort opened this issue Aug 18, 2020 · 3 comments
Open

Keep getting Error: Invalid schema content when I use define #191

steve-cuzzort opened this issue Aug 18, 2020 · 3 comments

Comments

@steve-cuzzort
Copy link

steve-cuzzort commented Aug 18, 2020

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)

@cdhowie
Copy link
Collaborator

cdhowie commented Aug 20, 2020

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.

@steve-cuzzort
Copy link
Author

That was it.

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

fixed it.

@e-plause
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants