@citrineos/base
Version:
The base module for OCPP v2.0.1 including all interfaces. This module is not intended to be used directly, but rather as a dependency for other modules.
31 lines • 1.16 kB
JavaScript
// Copyright (c) 2023 S44, LLC
// Copyright Contributors to the CitrineOS Project
//
// SPDX-License-Identifier: Apache 2.0
/**
* Decorators for module components.
*/
export const AS_HANDLER_METADATA = 'AS_HANDLER_METADATA';
/**
* Decorator function for OCPP modules to expose methods within module classes as handlers for given call action.
*
* @param {CallAction} action - the call action parameter
* @return {PropertyDescriptor} - the property descriptor
*/
export const AsHandler = function (protocol, action) {
return (target, propertyKey, descriptor) => {
if (!Reflect.hasMetadata(AS_HANDLER_METADATA, target.constructor)) {
Reflect.defineMetadata(AS_HANDLER_METADATA, [], target.constructor);
}
const handlers = Reflect.getMetadata(AS_HANDLER_METADATA, target.constructor);
handlers.push({
action: action,
protocol: protocol,
methodName: propertyKey,
method: descriptor.value,
});
Reflect.defineMetadata(AS_HANDLER_METADATA, handlers, target.constructor);
return descriptor;
};
};
//# sourceMappingURL=AsHandler.js.map