Better organization of tests & other files
This commit is contained in:
18
src/decorators/exclude.ts
Normal file
18
src/decorators/exclude.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
export const EXCLUDED_PROPERTIES_KEY = 'serde:excluded_properties';
|
||||
|
||||
/* tslint:disable:variable-name only-arrow-functions */
|
||||
/**
|
||||
* Adding this decorator prevents the property from being included in the object built by Serde.serialize()
|
||||
*/
|
||||
export function Exclude(): Function {
|
||||
return function (target: any, key: string): void {
|
||||
Reflect.defineMetadata(
|
||||
EXCLUDED_PROPERTIES_KEY,
|
||||
[
|
||||
...Reflect.getMetadata(EXCLUDED_PROPERTIES_KEY, target) || [],
|
||||
key
|
||||
],
|
||||
target
|
||||
);
|
||||
};
|
||||
}
|
||||
2
src/decorators/index.ts
Normal file
2
src/decorators/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from './exclude';
|
||||
export * from './pluck';
|
||||
18
src/decorators/pluck.ts
Normal file
18
src/decorators/pluck.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
export const PLUCK_PROPERTIES_KEY = 'serde:pluck_properties';
|
||||
|
||||
/**
|
||||
* Adding this decorator allows for plucking out an T[] or {T: v}[]
|
||||
*
|
||||
* @param field - use 'fieldName' when creating string|number[],
|
||||
* use ['fieldName'] when creating {[fieldName]: value}[]
|
||||
*/
|
||||
export function Pluck(field: string | string[]): Function {
|
||||
return function (target: any, key: string): void {
|
||||
Reflect.defineMetadata(PLUCK_PROPERTIES_KEY, {
|
||||
...Reflect.getMetadata(PLUCK_PROPERTIES_KEY, target) || {},
|
||||
...{ [key]: field }
|
||||
}, target);
|
||||
};
|
||||
}
|
||||
|
||||
/* tslint:enable:variable-name */
|
||||
Reference in New Issue
Block a user