Skip to content

Releases: Treacherous/treacherous

KAPOW - Localization support

30 Nov 21:15
Compare
Choose a tag to compare

Localization

So out the box Treacherous now has support for different locales and has separated the validation messages from the actual validation rules. As with everything else the rule name/code is used as the contract between the messages. By default en-us will be loaded (its bundled with the project), but you can easily add your own custom messages to this as well as adding your own languages to it.

The current implementation will work fine for most simple examples, but it has been built with extensibility in mind, so for those of you who use i18n based frameworks you can make your own custom ILocaleHandler implementations which can take the locale codes (i.e en-us and the tags then do the relevant transforming on them.

There is a page in the docs about this subject, containing an example async loader that could go to back ends/apis etc, so this should hopefully get people up and running in the multilingual world.

This is a first pass, so the implementation may mature a bit once there is more feedback but for now should hopefully make things a little easier for everyone.

(You can still override the message per property rule via the builder, but it is rare you would need to)

Minor linting tweaks

This update has a few minor changes around the codebase, mainly to bring things in line with the linter so the code is no longer using var and instead using more concise const or let as well as upping the TS version used.

Dropping AMD support

The AMD modules were rarely used, and most module packaging systems these days can cope with commonJS and es2015 modules, so this version bundles those 2 versions, the main pointing to a commonjs implementation, and the module definition for webpack and other tools pointing to the es2015 implementation to allow for tree shaking.

Major Updates Ahoy

14 Jun 14:20
Compare
Choose a tag to compare

This new version contains a few updates, some for everyone, some just for typescript users.

For Typescript people

So you can now use almost all validation group methods as async, which allows you to do the following:

let modelErrors = await validationGroup.getModelErrors();
console.log(modelErrors);

To support this we have added a dependency on tslib for the runtime component for this, which stops the crazy async/await output in every file.

For everyone else

Well we have added support for 2 new features, the first being composite rules which allow you to create validation rules that apply to the whole model, so in these instances you will be passed the model resolver and it is up to you how you validate the model. You can create pre-made ICompositeValidationRule objects or dynamic rules at builder time which will automatically create a bespoke implementation behind the scenes. Information about this can be found in the docs for ruleset building, but here is a simple example:

let ruleSet = createRuleset()
	.forProperty("number1").addRule("minValue", 1)
	.addDynamicRule("totalNumber",
		x => {
			 let total = x.resolve("number1") + x.resolve("number2");
			 return Promise.resolve(total > 10);
		},
		"The total is not greater than 10") // <- THIS CREATES A COMPOSITE RULE
	.build();

let model = {
	number1: 0,
	number2: 0
};

let valGroup = createGroup().build(model, ruleSet);

let initialErrors = await valGroup.getModelErrors(true);
expect(initialErrors).to.include.keys("number1");
expect(initialErrors).to.include.keys("totalNumber"); // <- VIRTUAL PROPERTY NAMES ARE OUTPUT IN ERRORS

The other addition is display names so you can now add display name hints to properties via the builder or ruleset which are exposed by validation groups. Internally this isn't really used by treacherous core, but it will be used within the view related libraries to allow you to output human readable display names for property errors in validation summaries rather than the name of the actual property, like so:

let displayName = "User's name";
let rulesetBuilder = new RulesetBuilder();
let ruleset = rulesetBuilder.create()
	.forProperty("username")
		.addRule("required")
		.withDisplayName(displayName) // <-- SET THE DISPLAY NAME
	.build();

let dummyModel = {
	username: ""
};

let validationGroup = createValidationGroupFor(dummyModel, ruleset);
let actualDisplayName = validationGroup.getPropertyDisplayName("username");  // <-- GET THE DISPLAY NAME

expect(actualDisplayName).to.equal(displayName);

Typescript intellisense for properties

15 Aug 13:10
Compare
Choose a tag to compare

This release brings in an optional improvement for typescript users where you can use intellisense to select your property within rules by supplying an action to select the property like so:

var ruleset = Treacherous.createRuleset<SomeModel>()
    .addProperty(x => x.SomeProperty)
    .addRule("required")
    .build();

This is completely optional and you can continue to use strings if you wish and should not effect any pure JS users.

Improved validation groups and separation of reactivity

15 Aug 13:09
Compare
Choose a tag to compare

This version has some breaking changes, which have simplified validation group objects and also made a separation between a reactive and non reactive validation group. There is also a major change to the way that you create a validation group which now returns a builder rather than an instance, this provides some more flexibility to consumers as well as allowing for more configuration options going forward.

See the breaking changes and docs for more information.

Packaging/Tooling Changes

07 Jul 12:02
Compare
Choose a tag to compare

This release moves away from the various different flavours of Treacherous and just outputs a single commonjs module for consumption. It also simplifies the tooling and to fit into this the tests have been re-written in typescript.

There is also support for wallaby in this release if you use Wallaby.

Removing Bluebird Dependency

29 Jun 09:47
Compare
Choose a tag to compare

This release removes the hard dependency on Bluebird and just replaces it with any ES6 compatible promise object, there is also the addition of a base regex rule for use in more complex scenarios, which is known as AdvancedRegexValidaitonRule.

Message Overrides & Rule Verification

29 Jun 09:53
Compare
Choose a tag to compare

This release adds support for message overriding on the rule builder, this will allow you to set your own messaging rules and a precursor to supporting other languages, as well as adding support for rule verification so when adding rules they need to have a name, however it also adds the ability to pass a builder the rule registry for confirming the rule names actually exist within the registry, this is an optional step for the developer though if required.

Refactors and fixes

29 Jun 09:56
Compare
Choose a tag to compare

This release is mainly tidying up of some internal code as well as adding minor fixes, so no major new features here.

Dependency Updates

29 Jun 10:00
Compare
Choose a tag to compare

So the dependencies being consumed by Treacherous are now coming from npm rather than github directly, as well adding a manual test running gulp script to provide a simpler way to run tests without IDE.

Refactors and fixes

29 Jun 09:59
Compare
Choose a tag to compare

This release primarily refactors out some of the complex code from within the validation group as well as simplifying other aspects of the code base.