1
0

Updating types

This commit is contained in:
2021-02-10 14:19:37 -06:00
parent 6c9ccd7f82
commit 0ce0e943f5
3 changed files with 8 additions and 8 deletions

View File

@@ -4,13 +4,13 @@ export const EXCLUDED_PROPERTIES_KEY = 'serde:excluded_properties';
/** /**
* Adding this decorator prevents the property from being included in the object built by Serde.serialize() * Adding this decorator prevents the property from being included in the object built by Serde.serialize()
*/ */
export function Exclude(): Function { export function Exclude(): PropertyDecorator {
return function (target: any, key: string): void { return function (target: Object, propertyKey: PropertyKey): void {
Reflect.defineMetadata( Reflect.defineMetadata(
EXCLUDED_PROPERTIES_KEY, EXCLUDED_PROPERTIES_KEY,
[ [
...Reflect.getMetadata(EXCLUDED_PROPERTIES_KEY, target) || [], ...Reflect.getMetadata(EXCLUDED_PROPERTIES_KEY, target) || [],
key propertyKey
], ],
target target
); );

View File

@@ -1,9 +1,9 @@
export function Memoize(propsToWatch?: string[]): Function { export function Memoize(propsToWatch?: string[]): MethodDecorator {
const hasPropsToWatch = typeof propsToWatch !== 'undefined' && Array.isArray(propsToWatch); const hasPropsToWatch = typeof propsToWatch !== 'undefined' && Array.isArray(propsToWatch);
if (typeof propsToWatch !== 'undefined' && !hasPropsToWatch) { if (typeof propsToWatch !== 'undefined' && !hasPropsToWatch) {
throw new Error('Somethings wrong with the propsToWatch Array'); throw new Error('Somethings wrong with the propsToWatch Array');
} }
return function(target: any, propertyKey: string, descriptor: PropertyDescriptor) { return function(target: Object, propertyKey: PropertyKey, descriptor: PropertyDescriptor) {
const originalMethod = descriptor.value; const originalMethod = descriptor.value;
descriptor.value = function(this: any, ...args: any[]) { descriptor.value = function(this: any, ...args: any[]) {
let modelKeyPart = this; let modelKeyPart = this;
@@ -11,7 +11,7 @@ export function Memoize(propsToWatch?: string[]): Function {
const filteredEntries = Object.entries(this).filter(([k,v]) => propsToWatch.includes(k)) const filteredEntries = Object.entries(this).filter(([k,v]) => propsToWatch.includes(k))
modelKeyPart = Object.fromEntries(filteredEntries); modelKeyPart = Object.fromEntries(filteredEntries);
} }
const reflectKey = `${JSON.stringify(modelKeyPart)}_${JSON.stringify(args)}_${propertyKey}`; const reflectKey = `${JSON.stringify(modelKeyPart)}_${JSON.stringify(args)}_${String(propertyKey)}`;
const hasReflectData = Reflect.hasMetadata(reflectKey, target); const hasReflectData = Reflect.hasMetadata(reflectKey, target);
if (hasReflectData) { if (hasReflectData) {

View File

@@ -6,8 +6,8 @@ export const PLUCK_PROPERTIES_KEY = 'serde:pluck_properties';
* @param field - use 'fieldName' when creating string|number[], * @param field - use 'fieldName' when creating string|number[],
* use ['fieldName'] when creating {[fieldName]: value}[] * use ['fieldName'] when creating {[fieldName]: value}[]
*/ */
export function Pluck(field: string | string[]): Function { export function Pluck(field: string | string[]): PropertyDecorator {
return function (target: any, key: string): void { return function (target: any, key: PropertyKey): void {
Reflect.defineMetadata(PLUCK_PROPERTIES_KEY, { Reflect.defineMetadata(PLUCK_PROPERTIES_KEY, {
...Reflect.getMetadata(PLUCK_PROPERTIES_KEY, target) || {}, ...Reflect.getMetadata(PLUCK_PROPERTIES_KEY, target) || {},
...{ [key]: field } ...{ [key]: field }