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

Extend describe() for type #1028

Merged
merged 4 commits into from
Nov 10, 2016
Merged

Conversation

lamchakchan
Copy link
Contributor

For the API object.type(). I'm extending the meta data storage of the constructor within the schema to be placed in options. Also extending any.describe() to project it to a new item schema within the rules array. This will help facilitate an object generation of the exact type specified by this API contract. Problem right now is that the type is translated to a name of type String and the ability to reproduce via Object.create() is lost since there is no way to cast it back to the original reference. Support is being added within felicity

Let me know if there is a better way of implementing this.

Using the Joi API

Joi.object().type(RegExp);

Storage within the schema

{
    _test: [{
        name: 'type',
        arg: 'RegExp',
        options: {
            ctor: [Function RegExp]  //This is new
        }
    }]
}

Within the Transform of any.describe()

{
    rules: [{
        name: 'type',
        arg: 'RegExp',
        ctor: [Function RegExp] //This is new
    }]
}

@lamchakchan lamchakchan changed the title Extend describe for type Extend describe() for type Nov 6, 2016
@AdriVanHoudt
Copy link
Contributor

felicity looks really cool 👍

@lamchakchan
Copy link
Contributor Author

Thank you!

@@ -656,6 +656,8 @@ internals.Object = class extends Any {
}

return this.createError('object.type', { type: name }, state, options);
}, {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the place to put it, the 2nd argument of _test holds the describe data.

@Marsup Marsup added the feature New functionality or improvement label Nov 6, 2016
@Marsup Marsup self-assigned this Nov 6, 2016
@Marsup Marsup added this to the 10.0.0 milestone Nov 6, 2016
@lamchakchan
Copy link
Contributor Author

Thank you @Marsup for reviewing this so quickly. I have some follow up questions.

I want to clarify that 2nd argument of _test currently is being passed name [String]. I can do one of 2 things. Replace that usage of name with the value of ctor. Or make it so that the second argument is an object containing both like this:

{
   name : <name value>,
   ctor : [Function <type>]
}

Your advice is greatly appreciated.

@Marsup
Copy link
Collaborator

Marsup commented Nov 6, 2016

The latter should be fine.

@lamchakchan
Copy link
Contributor Author

Just to follow up, I checked in new changes based on the recommendation of changes.

@Marsup Marsup merged commit aff2b4f into hapijs:master Nov 10, 2016
@Marsup
Copy link
Collaborator

Marsup commented Nov 10, 2016

Thanks.

@lock
Copy link

lock bot commented Jan 9, 2020

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 9, 2020
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature New functionality or improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants