This repository was archived by the owner on Dec 27, 2024. It is now read-only.
0.14.0
See: (Milestone 0.14.0)[https://github.com/sakuraapi/core/milestone/25?closed=1]
New Features
- #179 you can now send complex data as
contextfrommodel.toJson(...)and that context will be available toIJsonOptions.ToJsonand@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=nullwas being included in sub documents BeforeCreateandBeforeSaveare now properly rolled up so you can just import them from@sakuraapi/core.- #182 dependencies were updated
Breaking Changes
@Json({formatToJson:...})has been renamed totoJson@Json({formatFromJson:...})has been renamed tofromJson@FormatToJsonhas been renamed to@ToJson@FormatFromJsonhas been renamed to@FromJson- type
ToJsonFormatterhas been renamed toToJsonHandlerand its context parameter is now typeIContextinstead ofstring - type
FromJsonFormatterhas been renamed toFromJsonHandler - You'll have to import
IContextfrom@sakuraapi/corein all your modules for your models.
Possible Breaking Change
model._idis now initialized asundefinedrather thannull