hapijs / hapijs/joi

Custom extension questions regarding mutateRegister/mutateRebuild

Open
#2,934 0 comments 0 reactions 0 assignees View on GitHub
support
Dominant language
JavaScript
Stars
21.2k
Forks
1.5k
Avg merge
4h 57m
Merged PRs (30d)
14

Description

#### Support plan

* *is this issue currently blocking your project?* (yes/no): no
* *is this issue affecting a production system?* (yes/no): no

#### Context

* *node version*: v14.17.1
* *module version*: 17.4.2,
* *environment* (e.g. node, browser, native): node
* *used with* (e.g. hapi application, another framework, standalone, ...): hapi
* *any other relevant information*: Creating a custom extension, for a simple query-filter (eg. `Joi.filter().operator().value()`

#### How can we help?

I've successfully managed to create a custom extension for Joi to handle my `queryFilter`-objects. It works beatifully, but I just want to be sure that I'm doing it right - I haven't seen any weird behavior, since my usecase is pretty simple.

I've looked a lot of the internal code, and tried to follow how `.keys()` and `.array().items()` work. I just have a question regarding `mutateRegister` and `mutateRebuild`; basically, when do I need to call these?
I'm using a custom `term` to store "overrides" for the value-schema if `operators` are passed, inspired by `Object.pattern()`-code. Do I need to call `mutateRegister()` for the schema stored in the "term"? Do I need to `mutateRebuild` in the `method()`?

My extension basically parses a filter like `version=lte:2.26.1` to an object I use internally. It is used like this
```js
const versionFilterSchema = Joi.filter()
operator(Joi.string().valid('eq', 'in', 'lte'))
.value(Joi.string())
.value(Joi.string().pattern(), { operators: ['lte'] }) //apply pattern only for lte```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.