clarkie / dynogels

DynamoDB data mapper for node.js. Originally forked from https://github.com/ryanfitz/vogels
Other
490 stars 110 forks source link

dynogels.types.uuid() returning an Object #36

Closed charlesnoble closed 7 years ago

charlesnoble commented 7 years ago

Reinstalled my node_modules folder for the first time in 17 days and suddenly dynogels.types.uuid() is not returning a UUID, but returning an Object for some strange reason.

I kept receiving the error:

error: 'child "id" fails because ["id" must be a string] on ...

and on further investigation, id looked like:

     id: 
      { '0': 46,
        '1': 122,
        '2': 34,
        '3': 227,
        '4': 36,
        '5': 212,
        '6': 68,
        '7': 24,
        '8': 164,
        '9': 166,
        '10': 226,
        '11': 139,
        '12': 86,
        '13': 61,
        '14': 108,
        '15': 195,
        abortEarly: false,
        convert: true,
        allowUnknown: false,
        skipFunctions: false,
        stripUnknown: false,
        language: {},
        presence: 'optional',
        strip: false,
        noDefaults: false },

and my schema file looks like:

var schema = {
  id: dynogels.types.uuid(),

Not sure where this has come from and nothing else has changed and it was all previously working very well.

Thanks for the help! :+1:

clarkie commented 7 years ago

Hi, can you post your package.json file please? What version of Joi and Dynogels are you using?

charlesnoble commented 7 years ago

Wow, straight on it, great work!

package.json:

  "dependencies": {
    "dynogels": "^5.0.2",
    "joi": "^9.0.1",
  },

I tried updating both Joi and Dynogels, but the same issue.

cdhowie commented 7 years ago

The object shown looks suspiciously like the Joi options object. Can you post an MCVE of the issue?

I can't reproduce the behavior on my end; the type works as I would expect:

> require('.').types.uuid().validate();
{ error: null, value: '1c6102e1-b896-434e-a9f1-66d7016bc732' }
charlesnoble commented 7 years ago

I can reproduce those results too:

  let test = dynogels.types.uuid().validate();
  console.log(test)

Outputs:

{ error: null, value: '421ea917-c879-4d43-9d6b-ee1d72c11a22' }

I'll investigate more today and see what I can find.

charlesnoble commented 7 years ago

Temporarily I've implemented:

import { generateUUID } from '../utils/short-hash'

var schema = {
  id: Joi.string().guid().default(generateUUID),

and in short-hash.js:

import nodeUUID from 'node-uuid'

export let generateUUID = (context) => {
    return nodeUUID.v4()
}

generateUUID.description = 'uuid v4'

That seems to be working. I'll try to continue debugging the other issue later tomorrow.

csi-lk commented 7 years ago

Can reproduce this too on my end from a new install

package.json

    "dynogels": "^6.1.0",
    "joi": "^9.2.0",

Any version number I can drop to for the moment?

dylanswartz commented 7 years ago

Just started having this issue as well on a number of my services:

"dynogels": "^5.1.0",
"joi": "^9.0.4",

Looks like joi 9.2.0 gets installed. Locked it into 9.0.4 for a fix.

clarkie commented 7 years ago

you're right, this seems to break the tests too. npm i joi@9.0 && npm tnpm i joi@9.1 && npm tnpm i joi@9.2 && npm t ❌ I'm looking into what changed in 9.1

clarkie commented 7 years ago

Thanks for your help with this, I've raised an issue asking for help from the joi lot.