Releases: JaapRood/vry
Remove features deprecated in v2
Add defaults as option to type.factory
This version introduces defaults and the schema to be overridden when using state.factory
or model.factory
, as well as the schema (was already possible, but poorly documented). This allows for partial instances to be created that can then be merged with their more complete versions, while allowing to define defaults for client-only or base instances. This flexibility is instrumental in using Vry to model API resources.
Breaking Changes
While the API is purely additive, the new propagation behaviour of the defaults for models
, changes previously expected behaviour. The following now does something different:
const User = Model.create({
typeName: 'user',
defaults: {
name: 'Unknown Author'
}
})
const Post = Model.create({
typeName: 'post',
defaults: {
author: {}
},
schema: {
author: User
}
})
const post = Post.factory()
Before these changes, creating a new post
would create an embedded author
with the name Unknown Author
, with the defaults of the nested schema applied. Now, however, the defaults are propagated to the nested model. In this case, the post
would still have a User
model embedded as an author, but with it's defaults set to {}
, not have the default name
prop applied.
To get the old behaviour, you can use the model.defaults()
to explicitly set the defaults for the nested schema:
// ....
const Post = Model.create({
typeName: 'post',
defaults: {
author: User.defaults()
},
schema: {
author: User
}
})
Bugfix for mergeDeep when used with embedded types
Merge pull request #8 from JaapRood/fix/merge-deep Fix bug where non-instances were attempted to be merged as instances
Add mergeDeep to State, Model and IterableSchemas
v2.1.0 Bump version number
Forward options to item schemas
v2.0.3 Bump version number
Iterable schema fix
Merge pull request #5 from JaapRood/fix/iterable-schema Fix the applying of the item schema's factory and / or serialize methods by IterableSchema's
Model and Schema
This release adds Model
and Schema
concepts. In addition, the way State
has been implemented has changed significantly, causing a couple of breaking changes. The changes were to make sure a Model
can be like a State
, without creating an "is-a" relationship. Instead, both constructs are composed out and have things like a Factory
and Identity
.
Breaking changes
State.prototype
no longer has the methodsfactory
,merge
,parse
andserialize
. To use default behaviour when overriding one of these methods, they are available ontype.prototype
, wheretype
is the generated type withState.create
.- The metadata prop
__name
has been renamed to__typeName
. For future use be sure to use the newtype.typeName(instance)
to access the type name.
Deprecations
These changes will cause warnings and will be removed in the future.
State.serialize(instance, omitCid=true)
has changed toState.serialize(instance, options={omitCid: true})
.