Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// if (options.type && !isPrimitiveOrPrimitiveClass(options.type)) {
// return this.serializeClass(obj, options);
// }
if (typeof obj.toJSON === "function" && !obj.toJSON.$ignore) {
// deserialize from serialize method
return obj.toJSON();
}
// Default converter
if (!isPrimitiveOrPrimitiveClass(obj)) {
return this.serializeClass(obj, options);
}
} catch (err) {
/* istanbul ignore next */
throw err.name === "BAD_REQUEST" ? err : new ConverterSerializationError(getClass(obj), err);
}
/* istanbul ignore next */
return obj;
}
it("should return the class when prototype is given", () => {
expect(getClass(Test.prototype)).to.eq(Test);
});
});
it("should return the class when class is given", () => {
expect(getClass(Test)).to.eq(Test);
});
public bindInterceptor(instance: any, {propertyKey, useType, options}: IInjectablePropertyService) {
const target = getClass(instance);
const originalMethod = instance[propertyKey];
instance[propertyKey] = (...args: any[]) => {
const next = (err?: Error) => {
if (!err) {
return originalMethod.apply(instance, args);
}
throw err;
};
const context: IInterceptorContext = {
target,
method: propertyKey,
propertyKey,
args,
public bindMethod(instance: any, {propertyKey}: IInjectablePropertyService) {
const target = getClass(instance);
const originalMethod = instance[propertyKey];
const deps = Metadata.getParamTypes(prototypeOf(target), propertyKey);
instance[propertyKey] = () => {
const services = deps.map((dependency: any) => this.get(dependency));
return originalMethod.call(instance, ...services);
};
}
private checkStrictModelValidation(instance: any, propertyKey: string | symbol, propertyMetadata: PropertyMetadata | undefined) {
if (this.isStrictModelValidation(getClass(instance)) && propertyMetadata === undefined) {
throw new UnknownPropertyError(getClass(instance), propertyKey);
}
}
target.prototype.serialize = function(options: IConverterOptions, converterService: ConverterService) {
const {checkRequiredValue, ignoreCallback} = options;
return converterService.serializeClass(this, {
type: getClass(target),
checkRequiredValue,
ignoreCallback
});
};