0.17.0
See Milestone 0.17.0
What's new
#201 It's now possible to toggle @Json decorated properties as encryption:true, which causes them to be encrypted toJson and decrypted fromJson using the IJsonOptions.key property to define the cipher key. You can also define @Model({cipherKey: () => 'secret key'}) to define the key at the Model level. The cipherKey function will be called upon instantiation of a model and has access to the models instance via its this context.
#203 @Json({type: 'id'}) will now cause a property to be cast as an ObjectID by fromJson. Future supported types like Date are forthcoming.
Breaking Change
#202 _id must now be explicitly mapped to a property.
-
If you define a
dbConfigon your@Modelbut you do not declare a property decorated with@Id()you will get an error:Failed: Model SomeModelName defines 'dbConfig' but does not have an @Id decorated properties. To resolve this, create a property named something likeid: ObjectID;and decorate it with@Id(). -
To get your models back to the equivalent prior behavior (automatically including an
idfield that mapped to_idand was serializable to json), include the following in your models:
@Id() @Json({type: 'id'})
id: ObjectID;
- the
@Id()decorated property is now enumerable. Control its inclusion / exclusion like you would any other property.
Why?(!):
- Less magic - it's weird that
idis this magical property that's just sorta there. - You can use decorators like
@Json({type: 'id'})on your@Id()decorated property. - This means you can also do things like
@Json({encryption: true, type: 'id'})to encrypt your Ids.
Bug Fixes
#174 - toDb no longer injects undefined: undefined when a property is not decorated with @Db and the @Model is not promiscuous