I'm trying to use dynogels as an ORM for DynamoDB, but I can't get even the simplest example to work. No matter what I do typescript throws "Invalid schema content" error the moment I try and use it.
Run Command
ts-node main.ts
main.ts
import * as Dynogels from "dynogels";
import * as Joi from "joi";
// this comes out of an example on the dynogels github page
var BlogPost = Dynogels.define('BlogPost', {
hashKey : 'email',
rangeKey : 'title',
schema : {
email : Joi.string().email(),
title : Joi.string(),
content : Joi.string(),
tags : Dynogels.types.stringSet(),
}
});
console.log("this doesn't work")
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": {
"@types/dynogels": "^9.0.3",
"@types/joi": "^14.3.4",
"dynogels": "^9.1.0",
"joi": "^17.2.0",
"typescript": "^3.9.7"
}
}
When I run I get
StackOverflowPost/node_modules/dynogels/node_modules/joi/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/dynogels/node_modules/joi/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:55:10) at internals.Object.keys (/Users/stephencuzzort/Projects/StackOverflowPost/node_modules/dynogels/node_modules/joi/lib/types/object/index.js:352:35) at Object.exports.schema (/Users/stephencuzzort/Projects/StackOverflowPost/node_modules/dynogels/node_modules/joi/lib/cast.js:36:29) at internals.Object.keys (/Users/stephencuzzort/Projects/StackOverflowPost/node_modules/dynogels/node_modules/joi/lib/types/object/index.js:352:35) at Object.exports.schema (/Users/stephencuzzort/Projects/StackOverflowPost/node_modules/dynogels/node_modules/joi/lib/cast.js:36:29) at internals.Object.keys (/Users/stephencuzzort/Projects/StackOverflowPost/node_modules/dynogels/node_modules/joi/lib/types/object/index.js:352:35) at Joi.validate (/Users/stephencuzzort/Projects/StackOverflowPost/node_modules/dynogels/lib/schema.js:121:71) at internals.Object._validateWithOptions (/Users/stephencuzzort/Projects/StackOverflowPost/node_modules/dynogels/node_modules/joi/lib/types/any/index.js:666:20) at module.exports.internals.Any.root.validate (/Users/stephencuzzort/Projects/StackOverflowPost/node_modules/dynogels/node_modules/joi/lib/index.js:139:23)
Why do I keep getting this even when I use an example from the github page? How could I make this example work?
Found the problem. It was a joi
version mismatch.
You need to either make sure the joi
versions match exactly, or import from the dynogels node_modules
import * as Joi from "dynogels/node_modules/joi";
fixed it for me.