1.0.1 • Published 7 months ago
@maur025/core-commands v1.0.1
Overview
Utility library to declare and extend Command Pattern, inspired by the java implementation.
Installation
Use the following command to install:
Using pnpm:
pnpm add @maur025/core-commandsUsing npm:
npm install @maur025/core-commandsUsing yarn:
yarn add @maur025/core-commandsUsage
Using thi library is simple. Extend AbstractCommand class to create a command. Override the run method(required) and optionally validate for custom validations.
Example
Command (example.cmd.ts)
import { AbstractCommand } from "@maur025/core-commands";
export default class ExampleCmd extends AbstractCommand<Request, void> {
protected validate(request: Request): void {
console.log("VALIDATING...");
}
protected run(request: Request): void {
console.log("EXECUTING EXAMPLE...");
}
}
interface Request {
paramOne: string;
paramTwo: number;
paramN: string;
}Your can assign any value to the input and output. These can be declarated as interfaces, classes, or primitive types.
Usage in your code (example.controller.ts)
import ExampleCmd from "src/command/example.cmd.ts";
const exampleCmd = new ExampleCmd();
export default class ExampleController {
processData = (): void => {
exampleCmd
.withRequest({
paramOne: "example",
paramTwo: 2,
paramN: "any value",
})
.execute();
};
}Suggestions
To improve code maintainability and reduce verbosity, consider using a Dependency Injection (DI) container to handle command instantation.
For example:
- This avoids manually using
new ExampleCmd()in your classes. - Promote better separation and makes testing easier.
1.0.1
7 months ago
1.0.0
7 months ago
2.0.0-beta.9
7 months ago
2.0.0-beta.8
7 months ago
2.0.0-beta.7
7 months ago
2.0.0-beta.6
7 months ago
2.0.0-beta.5
7 months ago
2.0.0-beta.4
7 months ago
2.0.0-beta.3
7 months ago
2.0.0-beta.2
7 months ago
2.0.0-beta.1
7 months ago
2.0.0-beta.0
7 months ago