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

0.14.0

Choose a tag to compare

@etsuo etsuo released this 04 May 00:04
· 71 commits to develop since this release
ec0bde3

See: (Milestone 0.14.0)[https://github.com/sakuraapi/core/milestone/25?closed=1]

New Features

  • #179 you can now send complex data as context from model.toJson(...) and that context will be available to IJsonOptions.ToJson and @ToJson. For example:
      @Model()
      class Test extends SapiModelMixin() {
        @Json({
          toJson: (val: string, key:string, context: IContext) => {
              // context is what you passed in
              return val;
          }
        })
        aField = '';

        @ToJson()
        formatJson(json: any, model: TestComplexContext, context: IContext): any {
          // context is what you passed into 
          return json;
        }
     }
/// elsewhere
const json = test.toJson({someThingComplex: true, context: 'someContext'});

If you do not provide a context field, the context defaults to default. You can also pass in a simple string context like before or none at all (in which case your context is default).

  • #178 fixed bug where id=null was being included in sub documents
  • BeforeCreate and BeforeSave are now properly rolled up so you can just import them from @sakuraapi/core.
  • #182 dependencies were updated

Breaking Changes

  • @Json({formatToJson:...}) has been renamed to toJson
  • @Json({formatFromJson:...}) has been renamed to fromJson
  • @FormatToJson has been renamed to @ToJson
  • @FormatFromJson has been renamed to @FromJson
  • type ToJsonFormatter has been renamed to ToJsonHandler and its context parameter is now type IContext instead of string
  • type FromJsonFormatter has been renamed to FromJsonHandler
  • You'll have to import IContext from @sakuraapi/core in all your modules for your models.

Possible Breaking Change

  • model._id is now initialized as undefined rather than null