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

Add symbol() type #1562

Merged
merged 2 commits into from Aug 13, 2018
Merged

Add symbol() type #1562

merged 2 commits into from Aug 13, 2018

Conversation

kanongil
Copy link
Contributor

@kanongil kanongil commented Aug 7, 2018

For #1420. Let me know what you think.

const rule = Joi.symbol().map(map);
Helper.validate(rule, [
[1, true, null, symbols[0]],
[symbols[0], true, null, symbols[0]],
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why wouldn't it become symbols[2] ? Or else why accept symbols as key of a map ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, yeah I didn't write that test as I intended to.

However, it might makes sense to work as it does, since the implementation adds all map values to the valid() values, which is resolved before the mapping.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Then I would deny symbols as keys, that doesn't make sense to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, normally the mapping would work – it just doesn't in the case, since the symbol is also used as a value.

Anyway, I don't have a problem with removing it. We can always re-add later if it somehow makes sense.


describe() {

const description = Any.prototype.describe.call(this);
Copy link
Collaborator

Choose a reason for hiding this comment

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

That PR made me realize we could do this in ES6 now, see fd28a30.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I thought as well, but chose to copy the existing style.

@kanongil
Copy link
Contributor Author

kanongil commented Aug 7, 2018

One note: The Map() equal tests don't actually do anything, since it isn't yet supported in Hoek.deepEqual(). It just sees it as Hoek.deepEqual({}, {}).

@kanongil
Copy link
Contributor Author

kanongil commented Aug 7, 2018

Feedback has been applied. I also changed to use Util.inspect() to serialize the Map, rather than rely on JSON.stringify(), which breaks if it sees a BigInt.

@Marsup
Copy link
Collaborator

Marsup commented Aug 7, 2018

I think BigInt is an edge case here that we shouldn't necessarily care about. It's our 1st direct introduction of util in joi, hopefully it's not too big a hit for people building for browsers but I'd rather do without if we can.

@Marsup
Copy link
Collaborator

Marsup commented Aug 10, 2018

What do you think of going back to the previous stringifier ?

@kanongil
Copy link
Contributor Author

There is no "hit" for browser builds since util is already used in Hoek.

@Marsup
Copy link
Collaborator

Marsup commented Aug 10, 2018

Which you plan to remove in 6.0 according to hapijs/hoek#268 😉

@kanongil
Copy link
Contributor Author

kanongil commented Aug 10, 2018

Wow, you're right – Hoek would drop all direct usage of util. Though probably still included as a secondary reference in other node packages.

@Marsup
Copy link
Collaborator

Marsup commented Aug 11, 2018

If I'm reading joi-browser's analysis right, it is required by hoek, isemail, and assert. Hoek and isemail can clearly remove it, and assert has a PR for it. That's a 15kB win, not much indeed, but I've been trying to see if the bundle could be optimized lately.

@Marsup Marsup self-assigned this Aug 13, 2018
@Marsup Marsup added the feature New functionality or improvement label Aug 13, 2018
@Marsup Marsup added this to the 13.7.0 milestone Aug 13, 2018
@Marsup
Copy link
Collaborator

Marsup commented Aug 13, 2018

We'll see about all that later...

@Marsup Marsup merged commit da70a73 into hapijs:master Aug 13, 2018
Marsup added a commit that referenced this pull request Sep 29, 2018
@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
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.

None yet

2 participants