-
-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(common): Add @PropertySerialize / @PropertyDeserialize decorator
Closes: #572
- Loading branch information
Showing
13 changed files
with
1,511 additions
and
1,233 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -158,4 +158,4 @@ | |
"packages": "packages", | ||
"test": "test" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
packages/common/src/jsonschema/decorators/propertyDeserialize.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import {PropertyMetadata} from "../class/PropertyMetadata"; | ||
import {PropertyFn} from "./property"; | ||
|
||
/** | ||
* Call the function before property is deserialization. | ||
* | ||
* ## Example | ||
* | ||
* ```typescript | ||
* class Model { | ||
* @PropertyDeserialize(v => v + 1) | ||
* property: string; | ||
* } | ||
* ``` | ||
* | ||
* @param {Function} fn | ||
* @returns {Function} | ||
* @decorator | ||
* @converters | ||
* @jsonschema | ||
* @property | ||
*/ | ||
export function PropertyDeserialize(fn: (value: any) => any) { | ||
return PropertyFn((propertyMetadata: PropertyMetadata) => { | ||
propertyMetadata.onDeserialize = fn; | ||
}); | ||
} |
27 changes: 27 additions & 0 deletions
27
packages/common/src/jsonschema/decorators/propertySerialize.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import {PropertyMetadata} from "../class/PropertyMetadata"; | ||
import {PropertyFn} from "./property"; | ||
|
||
/** | ||
* Call the function after property serialization. | ||
* | ||
* ## Example | ||
* | ||
* ```typescript | ||
* class Model { | ||
* @PropertyDeserialize(v => v + 1) | ||
* property: string; | ||
* } | ||
* ``` | ||
* | ||
* @param {Function} fn | ||
* @returns {Function} | ||
* @decorator | ||
* @converters | ||
* @jsonschema | ||
* @property | ||
*/ | ||
export function PropertySerialize(fn: (value: any) => any) { | ||
return PropertyFn((propertyMetadata: PropertyMetadata) => { | ||
propertyMetadata.onSerialize = fn; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.