Skip to content
This repository was archived by the owner on Dec 27, 2024. It is now read-only.

0.17.0

Choose a tag to compare

@etsuo etsuo released this 23 May 01:50
· 46 commits to develop since this release
b86916f

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 dbConfig on your @Model but 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 like id: ObjectID; and decorate it with @Id().

  • To get your models back to the equivalent prior behavior (automatically including an id field that mapped to _id and 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?(!):

  1. Less magic - it's weird that id is this magical property that's just sorta there.
  2. You can use decorators like @Json({type: 'id'}) on your @Id() decorated property.
  3. 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