cqrs-eda
Version:
Lightweight CQRS and Event-Driven Architecture library using TypeScript decorators, handlers and typings. Perfect for scalable event-driven apps.
45 lines (44 loc) • 1.42 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.registerDecoratedClasses = registerDecoratedClasses;
/**
* Registers decorated classes (Commands, Queries, Observers) by importing them directly
* or by passing them as objects from `import * as ...`.
*
* This function automatically normalizes arrays and objects into arrays of classes,
* so you don't need to manually call Object.values().
*
* Example (array export in index.ts):
* ```ts
* import commandList from "@application/commands";
* import queryList from "@application/queries";
* import observerList from "@application/observers";
*
* registerDecoratedClasses({
* commands: commandList,
* queries: queryList,
* observers: observerList
* });
* ```
*
* Example (`import * as` style):
* ```ts
* import * as commandList from "@application/commands";
* import * as queryList from "@application/queries";
* import * as observerList from "@application/observers";
*
* registerDecoratedClasses({
* commands: commandList,
* queries: queryList,
* observers: observerList
* });
* ```
*/
function registerDecoratedClasses({ commands = [], queries = [], observers = [], }) {
const normalize = (list) => Array.isArray(list) ? list : Object.values(list);
[
...normalize(commands),
...normalize(queries),
...normalize(observers),
].forEach((cls) => void cls);
}