ObjectModel Versions Save

Strong Dynamically Typed Object Modeling for JavaScript

v3.2.0

6 years ago
  • ObjectModel instances enumerated keys behaviour has been changed to not include optional properties that are defined in the model definition but not assigned on the instance. This is required to resolve some issues with some external libraries integration.

v3.1.0

6 years ago
  • sealed models now prevent all undeclared properties at initial or future assignments, on direct and nested properties
  • add a params argument to object models constructor, i.e. Model(definition, { sealed: true })
  • add a dedicated section in the docs for sealed models
  • bugfix: assignments with null-safe traversal

v3.0.0

6 years ago

New features in v3

  • ES6 Proxies are used everywhere instead of ES5 property getters
  • New models: Map models and Set models
  • A custom devtool formatter in Chrome
  • sealed mode for object models to prevent undeclared properties
  • usable as ES Module: import { ObjectModel } from "objectmodel" to enable tree shaking

Breaking changes in v3

  • since v3 relies on ES6 Proxies, it is only usable on modern browsers: Edge 14+ / Firefox 47+ / Chrome 50+ / Node 6+
  • All the possible operations on objects, including special ones like delete, defineProperty or Object.keys, are now checked against the model definition. Consequently, new type errors could be found after upgrading.
  • Model.conventionForPrivate and Model.conventionForConstant have been moved to Model.prototype so that you can change these conventions specifically by model
  • Private properties are now private for real: you cannot use them outside of the model's own methods

Notes

This is almost a full rewrite of the library that I have been working on for over a year. ObjectModel is now written in ES6, has solid unit testing with over 400 assertions, and overall has much better mechanics to validate and cast your models. Enjoy !

v2.6.0

7 years ago
  • Basic, Object and Array model constructors now throws an error if no definition is provided
  • All the type errors now includes path information and have the same properties

v2.5.0

7 years ago
  • array models elements are now automatically casted to their suitable model if found
  • function models arguments and return values are now automatically casted to their suitable model if found
  • added support for yarn

v2.4.0

7 years ago
  • NaN and Invalid Date are now considered invalid for types Number and Date
  • function models instances called with invalid arguments are no longer executed
  • added model.defaultTo

v2.3.0

7 years ago
  • assertions now use try/catch to catch exceptions. When an exception is catched, the assertion fails and the exception is passed to the error collector
  • TypeError messages have been improved, especially for assertion failures. It now indicates the value tested and what the assertion returned.

v2.2.0

7 years ago

When constructing a composed object model, properties are automatically casted to model instances according to the definition. Now, this also works for union types. If several models are suitable within a union type, there is an ambiguity and the object will be left untouched with a warning console message.

See https://github.com/sylvainpolletvillard/ObjectModel/issues/24 for details

v2.1.0

7 years ago
  • assertions are now inherited from Model.prototype, which enables you to add global assertions
  • assertions now require to return true to validate. Truthy values do not pass anymore
  • assertions error messages can now be functions called with the assertion result as argument

v1.0.0

7 years ago
v1.0
added model.validate and model.test
moved conventions to overridable exposed functions
preserve object properties out of model definition at instanciation
aligned array models constructors with other models behaviour