ts-jackson
Advanced tools
Comparing version 1.2.3 to 1.2.4
import 'reflect-metadata'; | ||
/** | ||
* Function to deserialize json to Serializable class | ||
* | ||
* @param {Record<string, unknown>} json | ||
* @param serializableClass Class to which json should be serialized | ||
* @param args an arguments to be provided to constructor. | ||
* For example Cat(readonly name, readonly color) | ||
* deserialize({}, Cat, 'Moon', 'black') | ||
*/ | ||
export default function deserialize<T, U extends Array<unknown>>(json: Record<string, unknown>, serializableClass: new (...params: [...U]) => T, ...args: U): T; |
@@ -0,2 +1,22 @@ | ||
/** | ||
* @author Ilias Gazdaliev <invimind@gmail.com> | ||
*/ | ||
import 'reflect-metadata'; | ||
/** | ||
* JsonProperty params | ||
* | ||
* @param {string} path -- path pattern for the property | ||
* supports every pattern provided by lodash/get|set object | ||
* @param {boolean} required throws an Error if json is missing required property | ||
* @param {Function} type Optional. In most cases there is no need to specify | ||
* type explicitly | ||
* @param {Function} elementType due to reflect-metadata restriction one should | ||
* explicitly set elementType property to correctly serialize/deserialize Array | ||
* or Set values | ||
* @param {Function} validate function for validating json values. Throws an error | ||
* if property fails to pass validate check | ||
* @param {Function} deserialize function for custom deserialization | ||
* @param {Function} serialize function for custom serialization | ||
* @param {Function} afterDeserialize takes deserialized instance and deserialized property. Should return new property value. | ||
*/ | ||
declare type Params<P> = { | ||
@@ -17,3 +37,7 @@ path?: string; | ||
} & Params<P>; | ||
/** | ||
* Decorator. Collects annotated property metadata. | ||
* @param {string | Params} arg | ||
*/ | ||
export default function JsonProperty<P = unknown>(arg?: Params<P> | string): (object: Object, propertyName: string) => void; | ||
export {}; |
@@ -0,1 +1,4 @@ | ||
/** | ||
* @author Ilias Gazdaliev <invimind@gmail.com> | ||
*/ | ||
import 'reflect-metadata'; | ||
@@ -6,3 +9,8 @@ declare type Params = {}; | ||
} & Params; | ||
/** | ||
* Decorator for marking serializable classes | ||
* | ||
* @returns {Record<string, unknown>} json | ||
*/ | ||
export default function Serializable(): (target: new (...params: Array<unknown>) => unknown) => void; | ||
export {}; |
@@ -0,1 +1,7 @@ | ||
/** | ||
* Function to serialize Serializable class to json | ||
* | ||
* @param {Function} instance serializable instance | ||
* @returns {Record<string, unknown>} json | ||
*/ | ||
export default function serialize<T extends new (...args: any[]) => unknown>(instance: InstanceType<T>): Record<string, unknown>; |
{ | ||
"name": "ts-jackson", | ||
"version": "1.2.3", | ||
"version": "1.2.4", | ||
"author": "Ilias Gazdaliev", | ||
@@ -5,0 +5,0 @@ "description": "", |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
31848
24
178