webezy-io/commons
This is commons modules to be used with Webezy.io project written in TS / JS
Install
Install the package via npm:
npm i --save @webezy-io/commons
Usage
@webezy-io/commons is used for common method on Webezy.io projects including with client or server side TS / JS code.
Validators
This is sample use case if a validator is attached to one of your incoming messages. It will validate input against the calidator logic, and will fail the request before sending it to server.
import { utils } from '@webezy-io/commons';
class project() {
public SampleRPC(params: SampleMsg, metadata: Metadata = this.metadata): Promise<SampleMsg> {
utils.validators._min_validator(params.SampleInt, 10.0)
return promisify<SampleMsg, Metadata, SampleMsg>(this.SampleService_client.sampleRPC.bind(this.SampleService_client))(params, metadata);
}
}
See Docs on how to attach validators in Webezy.io project.
Use to generate message with extandable fields.
wz generate --message --field-extension
Available validators
- webezy.commons.v1.Validators.Email - Email string validator
- webezy.commons.v1.Validators.RegEx - A custom regular expression validation
- webezy.commons.v1.Validators.MaxLength - Maximum length of a String or Array
- webezy.commons.v1.Validators.Max - Minimum value
- webezy.commons.v1.Validators.Max - Maximum value