Metal.js AOP Utility

3.0.0 · abandoned · verified Sun Apr 19

metal-aop is a utility package that provides Aspect-Oriented Programming (AOP) capabilities specifically for applications built with the Metal.js framework. AOP allows developers to modularize cross-cutting concerns such as logging, security, and transaction management, by defining advice (code to be executed) and applying it at specific join points (execution points) in the application's flow. The package's latest stable version is 3.0.0, released approximately eight years ago. However, the underlying Metal.js framework has been officially deprecated by Liferay, its primary maintainer, with no active staffing for open-source support and no future plans to use the framework. Consequently, metal-aop is effectively an abandoned project, meaning it receives no new features, bug fixes, or security patches. Its differentiators were primarily its tight integration with Metal.js's component model, which is no longer actively developed.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to apply 'before', 'after', and 'around' advice to methods of a class using metal-aop, illustrating basic Aspect-Oriented Programming (AOP) concepts like interception.

const Aop = require('metal-aop');

class MyService {
  doSomething(data) {
    console.log(`Processing data: ${data}`);
    return `Result for ${data}`;
  }

  anotherMethod() {
    console.log('Another method called.');
  }
}

const myServiceInstance = new MyService();

// Define a 'before' advice
Aop.before(myServiceInstance, 'doSomething', function(originalArgs) {
  console.log(`[AOP-Before] Preparing to call doSomething with: ${originalArgs[0]}`);
});

// Define an 'after' advice
Aop.after(myServiceInstance, 'doSomething', function(originalArgs, result) {
  console.log(`[AOP-After] doSomething finished. Original args: ${originalArgs[0]}, Result: ${result}`);
});

// Define an 'around' advice
Aop.around(myServiceInstance, 'anotherMethod', function(originalFn) {
  console.log('[AOP-Around] Before calling anotherMethod');
  const result = originalFn(); // Call the original method
  console.log('[AOP-Around] After calling anotherMethod');
  return result;
});

console.log('--- Calling doSomething ---');
myServiceInstance.doSomething('input123');

console.log('\n--- Calling anotherMethod ---');
myServiceInstance.anotherMethod();

view raw JSON →