Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@moirae/core

Package Overview
Dependencies
Maintainers
3
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@moirae/core - npm Package Compare versions

Comparing version 0.4.2 to 0.5.3

.rush/temp/operation/build/state.json

11

dist/index.d.ts

@@ -22,2 +22,3 @@ export { CommandBus } from "./lib/busses/command.bus";

export { AddMixin, applyMixins } from "./lib/decorators/mixin.decorator";
export { MoiraeFilter } from "./lib/decorators/moirae-filter.decorator";
export { Projection } from "./lib/decorators/projection.decorator";

@@ -28,2 +29,3 @@ export { QueryHandler } from "./lib/decorators/query-handler.decorator";

export { SagaStep } from "./lib/decorators/saga-step.decorator";
export { InvalidConfigurationError } from "./lib/exceptions/invalid-configuration.error";
export { AggregateFactory } from "./lib/factories/aggregate.factory";

@@ -43,4 +45,9 @@ export { ObservableFactory } from "./lib/factories/observable.factory";

export type { IHandler } from "./lib/interfaces/handler.interface";
export type { IInjectorReturn, InjectorFunction, } from "./lib/interfaces/injector.interface";
export type { IMemoryCacheConfig } from "./lib/interfaces/memory-cache-config.interface";
export type { IMemoryPublisherConfig } from "./lib/interfaces/memory-publisher-config.interface";
export type { IMemoryStoreConfig } from "./lib/interfaces/memory-store-config.interface";
export type { IMoiraeFilter } from "./lib/interfaces/moirae-filter.interface";
export type { IPubSub } from "./lib/interfaces/pub-sub.interface";
export type { IPublisherConfig } from "./lib/interfaces/publisher-config.interface";
export type { IPublisherConfig, IPublisherMeta, } from "./lib/interfaces/publisher-config.interface";
export type { IPublisher } from "./lib/interfaces/publisher.interface";

@@ -54,5 +61,5 @@ export type { IQueryHandler } from "./lib/interfaces/query-handler.interface";

export { EventProcessor } from "./lib/mixins/event-processor.mixin";
export { CACHE_OPTIONS, ESState, EVENT_PUBSUB_ENGINE, EVENT_SOURCE, PUBLISHER, PublisherRole, PUBLISHER_OPTIONS, } from "./lib/moirae.constants";
export { CACHE_OPTIONS, CACHE_PROVIDER, COMMAND_PUBLISHER, ESState, EVENT_PUBLISHER, EVENT_PUBSUB_ENGINE, EVENT_SOURCE, PUBLISHER_OPTIONS, QUERY_PUBLISHER, PublisherToken, } from "./lib/moirae.constants";
export { MoiraeModule } from "./lib/moirae.module";
export { MemoryPublisher } from "./lib/publishers/memory.publisher";
export { mockAggregateFactory } from "./lib/testing/aggregate-factory.mock";

13

dist/index.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.mockAggregateFactory = exports.MemoryPublisher = exports.MoiraeModule = exports.PUBLISHER_OPTIONS = exports.PublisherRole = exports.PUBLISHER = exports.EVENT_SOURCE = exports.EVENT_PUBSUB_ENGINE = exports.ESState = exports.CACHE_OPTIONS = exports.EventProcessor = exports.EventType = exports.ObservableFactory = exports.AggregateFactory = exports.SagaStep = exports.Rollback = exports.RegisterType = exports.QueryHandler = exports.Projection = exports.applyMixins = exports.AddMixin = exports.EventHandler = exports.CommandHandler = exports.Apply = exports.StateTracker = exports.Saga = exports.SagaManager = exports.ResponseWrapper = exports.Query = exports.Explorer = exports.Event = exports.Distributor = exports.Command = exports.CommandResponse = exports.BasePublisher = exports.BaseCache = exports.AsyncMap = exports.AggregateRoot = exports.QueryBus = exports.EventBus = exports.CommandBus = void 0;
exports.mockAggregateFactory = exports.MemoryPublisher = exports.MoiraeModule = exports.QUERY_PUBLISHER = exports.PUBLISHER_OPTIONS = exports.EVENT_SOURCE = exports.EVENT_PUBSUB_ENGINE = exports.EVENT_PUBLISHER = exports.ESState = exports.COMMAND_PUBLISHER = exports.CACHE_PROVIDER = exports.CACHE_OPTIONS = exports.EventProcessor = exports.EventType = exports.ObservableFactory = exports.AggregateFactory = exports.InvalidConfigurationError = exports.SagaStep = exports.Rollback = exports.RegisterType = exports.QueryHandler = exports.Projection = exports.MoiraeFilter = exports.applyMixins = exports.AddMixin = exports.EventHandler = exports.CommandHandler = exports.Apply = exports.StateTracker = exports.Saga = exports.SagaManager = exports.ResponseWrapper = exports.Query = exports.Explorer = exports.Event = exports.Distributor = exports.Command = exports.CommandResponse = exports.BasePublisher = exports.BaseCache = exports.AsyncMap = exports.AggregateRoot = exports.QueryBus = exports.EventBus = exports.CommandBus = void 0;
// busses

@@ -50,2 +50,4 @@ var command_bus_1 = require("./lib/busses/command.bus");

Object.defineProperty(exports, "applyMixins", { enumerable: true, get: function () { return mixin_decorator_1.applyMixins; } });
var moirae_filter_decorator_1 = require("./lib/decorators/moirae-filter.decorator");
Object.defineProperty(exports, "MoiraeFilter", { enumerable: true, get: function () { return moirae_filter_decorator_1.MoiraeFilter; } });
var projection_decorator_1 = require("./lib/decorators/projection.decorator");

@@ -61,2 +63,5 @@ Object.defineProperty(exports, "Projection", { enumerable: true, get: function () { return projection_decorator_1.Projection; } });

Object.defineProperty(exports, "SagaStep", { enumerable: true, get: function () { return saga_step_decorator_1.SagaStep; } });
// errors
var invalid_configuration_error_1 = require("./lib/exceptions/invalid-configuration.error");
Object.defineProperty(exports, "InvalidConfigurationError", { enumerable: true, get: function () { return invalid_configuration_error_1.InvalidConfigurationError; } });
// factories

@@ -75,8 +80,10 @@ var aggregate_factory_1 = require("./lib/factories/aggregate.factory");

Object.defineProperty(exports, "CACHE_OPTIONS", { enumerable: true, get: function () { return moirae_constants_1.CACHE_OPTIONS; } });
Object.defineProperty(exports, "CACHE_PROVIDER", { enumerable: true, get: function () { return moirae_constants_1.CACHE_PROVIDER; } });
Object.defineProperty(exports, "COMMAND_PUBLISHER", { enumerable: true, get: function () { return moirae_constants_1.COMMAND_PUBLISHER; } });
Object.defineProperty(exports, "ESState", { enumerable: true, get: function () { return moirae_constants_1.ESState; } });
Object.defineProperty(exports, "EVENT_PUBLISHER", { enumerable: true, get: function () { return moirae_constants_1.EVENT_PUBLISHER; } });
Object.defineProperty(exports, "EVENT_PUBSUB_ENGINE", { enumerable: true, get: function () { return moirae_constants_1.EVENT_PUBSUB_ENGINE; } });
Object.defineProperty(exports, "EVENT_SOURCE", { enumerable: true, get: function () { return moirae_constants_1.EVENT_SOURCE; } });
Object.defineProperty(exports, "PUBLISHER", { enumerable: true, get: function () { return moirae_constants_1.PUBLISHER; } });
Object.defineProperty(exports, "PublisherRole", { enumerable: true, get: function () { return moirae_constants_1.PublisherRole; } });
Object.defineProperty(exports, "PUBLISHER_OPTIONS", { enumerable: true, get: function () { return moirae_constants_1.PUBLISHER_OPTIONS; } });
Object.defineProperty(exports, "QUERY_PUBLISHER", { enumerable: true, get: function () { return moirae_constants_1.QUERY_PUBLISHER; } });
// modules

@@ -83,0 +90,0 @@ var moirae_module_1 = require("./lib/moirae.module");

@@ -0,1 +1,2 @@

import { InstanceWrapper } from "@nestjs/core/injector/instance-wrapper";
import { BaseBus } from "../classes/base.bus";

@@ -7,3 +8,2 @@ import { CommandResponse } from "../classes/command-response.class";

import { ICommand } from "../interfaces/command.interface";
import { ExecuteOptions } from "../interfaces/execute-options.interface";
import { IPublisher } from "../interfaces/publisher.interface";

@@ -16,5 +16,7 @@ /**

private readonly _sagaManager;
private readonly _errorHandlers;
constructor(explorer: Explorer, observableFactory: ObservableFactory, publisher: IPublisher, _sagaManager: SagaManager);
execute<TRes = CommandResponse>(command: ICommand, options?: ExecuteOptions): Promise<TRes>;
protected executeLocal(command: ICommand): Promise<CommandResponse>;
execute<TRes = CommandResponse>(command: ICommand): Promise<TRes>;
protected executeLocal(command: ICommand): Promise<void>;
protected handleInstanceImport(instance: InstanceWrapper["instance"]): void;
}

@@ -17,10 +17,7 @@ "use strict";

const common_1 = require("@nestjs/common");
const class_transformer_1 = require("class-transformer");
const crypto_1 = require("crypto");
const base_bus_1 = require("../classes/base.bus");
const command_response_class_1 = require("../classes/command-response.class");
const constructor_storage_class_1 = require("../classes/constructor-storage.class");
const explorer_class_1 = require("../classes/explorer.class");
const saga_manager_class_1 = require("../classes/saga-manager.class");
const command_execution_error_1 = require("../exceptions/command-execution.error");
const observable_factory_1 = require("../factories/observable.factory");

@@ -36,40 +33,44 @@ const moirae_constants_1 = require("../moirae.constants");

this._sagaManager = _sagaManager;
this._publisher.role = moirae_constants_1.PublisherRole.COMMAND_BUS;
this._publisher.role = moirae_constants_1.COMMAND_PUBLISHER;
this._errorHandlers = new Map();
}
async execute(command, options) {
async execute(command) {
if (!command.$correlationId)
command.$correlationId = (0, crypto_1.randomUUID)();
const response = await super.execute(command, options);
if ((options === null || options === void 0 ? void 0 : options.throwError) && response.error) {
const ErrorConstructor = constructor_storage_class_1.ConstructorStorage.getInstance().get(response.error.name);
if (ErrorConstructor) {
throw (0, class_transformer_1.plainToInstance)(ErrorConstructor, response.error);
}
else {
throw new command_execution_error_1.CommandExecutionError(command);
}
if (!command.STREAM_ID)
command.STREAM_ID = (0, crypto_1.randomUUID)();
if (!command.$executionDomain)
command.$executionDomain = "default";
if (command.$executionDomain === this._publisher.domain) {
await this.executeLocal(command);
}
return response;
else {
await this._publisher.publish(command);
}
return command_response_class_1.CommandResponse.fromCommand(command);
}
async executeLocal(command) {
this._status.set(moirae_constants_1.ESState.ACTIVE);
const response = new command_response_class_1.CommandResponse();
response.correlationId = command.$correlationId;
response.streamId = command.STREAM_ID || (0, crypto_1.randomUUID)();
const _streamId = command.STREAM_ID || (0, crypto_1.randomUUID)();
const res = await super.executeLocal(command, {
streamId: response.streamId,
streamId: _streamId,
});
response.success = !(res instanceof Error);
if (!response.success) {
if (res instanceof Error) {
const rollbackCommands = await this._sagaManager.rollbackSagas(command.$correlationId);
await Promise.all(rollbackCommands.map((c) => this.publish(c)));
response.error = res;
if (this._errorHandlers.has(res.name))
await this._errorHandlers.get(res.name).catch(command, res);
}
this._status.set(moirae_constants_1.ESState.IDLE);
return response;
}
handleInstanceImport(instance) {
if (Reflect.hasMetadata(moirae_constants_1.EXCEPTION_METADATA, instance.constructor)) {
const err = Reflect.getMetadata(moirae_constants_1.EXCEPTION_METADATA, instance.constructor);
this._errorHandlers.set(err.name, instance);
}
}
};
CommandBus = __decorate([
(0, common_1.Injectable)(),
__param(2, (0, common_1.Inject)(moirae_constants_1.PUBLISHER)),
__param(2, (0, common_1.Inject)(moirae_constants_1.COMMAND_PUBLISHER)),
__metadata("design:paramtypes", [explorer_class_1.Explorer,

@@ -76,0 +77,0 @@ observable_factory_1.ObservableFactory, Object, saga_manager_class_1.SagaManager])

@@ -54,3 +54,2 @@ "use strict";

command.$correlationId = event.$correlationId;
command.$disableResponse = true;
return this.commandBus.publish(command);

@@ -57,0 +56,0 @@ }));

import { BaseBus } from "../classes/base.bus";
import { Explorer } from "../classes/explorer.class";
import { ObservableFactory } from "../factories/observable.factory";
import { ExecuteOptions } from "../interfaces/execute-options.interface";
import { IPublisher } from "../interfaces/publisher.interface";

@@ -12,2 +13,6 @@ import { IQuery } from "../interfaces/query.interface";

constructor(explorer: Explorer, observableFactory: ObservableFactory, publisher: IPublisher);
/**
* Execute the provided query on a remote system
*/
execute<TRes>(query: IQuery, options?: ExecuteOptions): Promise<TRes>;
}

@@ -17,2 +17,3 @@ "use strict";

const common_1 = require("@nestjs/common");
const crypto_1 = require("crypto");
const base_bus_1 = require("../classes/base.bus");

@@ -29,8 +30,30 @@ const explorer_class_1 = require("../classes/explorer.class");

super(explorer, moirae_constants_1.QUERY_METADATA, observableFactory, publisher);
this._publisher.role = moirae_constants_1.PublisherRole.QUERY_BUS;
this._publisher.role = moirae_constants_1.QUERY_PUBLISHER;
}
/**
* Execute the provided query on a remote system
*/
async execute(query, options = {}) {
const { throwError = false } = options;
const _key = (0, crypto_1.randomUUID)();
query.$responseKey = _key;
let res;
if (!query.$executionDomain)
query.$executionDomain = "default";
if (query.$executionDomain === this._publisher.domain) {
res = (await this.executeLocal(query, options));
}
else {
await this._publisher.publish(query);
const external = await this._publisher.awaitResponse(_key);
if (external.payload instanceof Error && throwError)
throw external.payload;
res = external.payload;
}
return res;
}
};
QueryBus = __decorate([
(0, common_1.Injectable)(),
__param(2, (0, common_1.Inject)(moirae_constants_1.PUBLISHER)),
__param(2, (0, common_1.Inject)(moirae_constants_1.QUERY_PUBLISHER)),
__metadata("design:paramtypes", [explorer_class_1.Explorer,

@@ -37,0 +60,0 @@ observable_factory_1.ObservableFactory, Object])

import { OnApplicationBootstrap } from "@nestjs/common";
import { InstanceWrapper } from "@nestjs/core/injector/instance-wrapper";
import { ObservableFactory } from "../factories/observable.factory";
import { ExecuteOptions } from "../interfaces/execute-options.interface";
import { IHandler } from "../interfaces/handler.interface";

@@ -20,9 +20,6 @@ import { IPublisher } from "../interfaces/publisher.interface";

/**
* Execute the provided command or query on a remote system
*/
execute<TRes>(event: T, options?: ExecuteOptions): Promise<TRes>;
/**
* @internal Should not be used outside of the context of the library
*/
protected executeLocal(event: T, options: Record<string, unknown>): Promise<unknown>;
protected handleInstanceImport(instance: InstanceWrapper<any>["instance"]): void;
onApplicationBootstrap(): void;

@@ -29,0 +26,0 @@ publish(event: T): Promise<void>;

@@ -5,3 +5,2 @@ "use strict";

const common_1 = require("@nestjs/common");
const crypto_1 = require("crypto");
const handler_not_found_error_1 = require("../exceptions/handler-not-found.error");

@@ -19,17 +18,2 @@ const moirae_constants_1 = require("../moirae.constants");

/**
* Execute the provided command or query on a remote system
*/
async execute(event, options = {}) {
const { throwError = false } = options;
const _key = (0, crypto_1.randomUUID)();
event.$responseKey = _key;
if (!event.$executionDomain)
event.$executionDomain = "default";
await this._publisher.publish(event);
const res = await this._publisher.awaitResponse(_key);
if (res.payload instanceof Error && throwError)
throw res.payload;
return res.payload;
}
/**
* @internal Should not be used outside of the context of the library

@@ -51,2 +35,5 @@ */

}
handleInstanceImport(instance) {
// stub
}
onApplicationBootstrap() {

@@ -62,2 +49,3 @@ this._status.set(moirae_constants_1.ESState.PREPARING);

}
this.handleInstanceImport(instance);
});

@@ -68,2 +56,4 @@ this._publisher.subscribe(this.executeLocal.bind(this));

publish(event) {
if (!event.$executionDomain)
event.$executionDomain = "default";
return this._publisher.publish(event);

@@ -70,0 +60,0 @@ }

import { BeforeApplicationShutdown, OnApplicationBootstrap } from "@nestjs/common";
import { AsyncMap } from "../classes/async-map.class";
import { ObservableFactory } from "../factories/observable.factory";
import { IPublisherConfig } from "../interfaces/publisher-config.interface";
import { IPublisherConfig, IPublisherMeta } from "../interfaces/publisher-config.interface";
import { Respondable } from "../interfaces/respondable.interface";
import { EventProcessor } from "../mixins/event-processor.mixin";
import { ESState, PublisherRole } from "../moirae.constants";
import { ESState, PublisherToken } from "../moirae.constants";
import { Distributor } from "./distributor.class";

@@ -13,3 +13,3 @@ import { ResponseWrapper } from "./response.class";

export declare abstract class BasePublisher<Evt extends Respondable> extends EventProcessor<Evt> implements OnApplicationBootstrap, BeforeApplicationShutdown, EventProcessor<Evt> {
protected readonly publisherOptions: IPublisherConfig;
protected readonly publisherOptions: IPublisherMeta;
protected _distributor: Distributor<Evt>;

@@ -19,5 +19,10 @@ protected _responseMap: AsyncMap<ResponseWrapper<unknown>>;

protected readonly _uuid: string;
role: PublisherRole;
constructor(observableFactory: ObservableFactory, publisherOptions: IPublisherConfig);
role: PublisherToken;
constructor(observableFactory: ObservableFactory, publisherOptions: IPublisherMeta);
get domain(): string;
protected get _key(): string;
/**
* Get specific configuration given the publisher role
*/
protected getRoleConfig<T extends IPublisherConfig>(): T;
acknowledgeEvent(event: Evt): Promise<void>;

@@ -24,0 +29,0 @@ awaitResponse(responseKey: string): Promise<ResponseWrapper<unknown>>;

@@ -19,5 +19,21 @@ "use strict";

}
get domain() {
return this.publisherOptions.domain || "default";
}
get _key() {
return `${this._uuid}:${exports.EVENT_KEY}`;
}
/**
* Get specific configuration given the publisher role
*/
getRoleConfig() {
switch (this.role) {
case moirae_constants_1.COMMAND_PUBLISHER:
return this.publisherOptions["command"];
case moirae_constants_1.EVENT_PUBLISHER:
return this.publisherOptions["event"];
case moirae_constants_1.QUERY_PUBLISHER:
return this.publisherOptions["query"];
}
}
async acknowledgeEvent(event) {

@@ -24,0 +40,0 @@ this._status.set(moirae_constants_1.ESState.IDLE);

@@ -0,1 +1,2 @@

import { ICommand } from "../interfaces/command.interface";
/**

@@ -10,8 +11,7 @@ * Response from a command execution. Reading the result should happen

correlationId: string;
error?: Error;
/**
* StreamID of the aggregate processed
*/
streamId?: string;
success: boolean;
streamId: string;
static fromCommand(command: ICommand): CommandResponse;
}

@@ -8,2 +8,3 @@ "use strict";

};
var CommandResponse_1;
Object.defineProperty(exports, "__esModule", { value: true });

@@ -16,5 +17,11 @@ exports.CommandResponse = void 0;

*/
let CommandResponse = class CommandResponse {
let CommandResponse = CommandResponse_1 = class CommandResponse {
static fromCommand(command) {
const response = new CommandResponse_1();
response.correlationId = command.$correlationId;
response.streamId = command.STREAM_ID;
return response;
}
};
CommandResponse = __decorate([
CommandResponse = CommandResponse_1 = __decorate([
(0, register_type_decorator_1.RegisterType)()

@@ -21,0 +28,0 @@ ], CommandResponse);

@@ -6,5 +6,3 @@ import { EventType } from "../interfaces/event-like.interface";

$executionDomain: "default" | string;
$responseKey: string;
$routingKey: string;
readonly $type = EventType.COMMAND;
}

@@ -10,3 +10,3 @@ import { OnApplicationBootstrap } from "@nestjs/common";

*
* The saga should be extended with a series of methods decorated with the {@link core.SagaStep} decorator where
* The saga should be extended with a series of methods decorated with the {@link @moirae/core!SagaStep} decorator where
* each method defines the `IF... THEN...` progression of the saga.

@@ -13,0 +13,0 @@ */

@@ -17,3 +17,3 @@ "use strict";

*
* The saga should be extended with a series of methods decorated with the {@link core.SagaStep} decorator where
* The saga should be extended with a series of methods decorated with the {@link @moirae/core!SagaStep} decorator where
* each method defines the `IF... THEN...` progression of the saga.

@@ -20,0 +20,0 @@ */

@@ -5,3 +5,3 @@ import { ClassConstructor } from "class-transformer";

/**
* Define a step in a saga. Related to {@link core.Saga}
* Define a step in a saga. Related to {@link @moirae/core!Saga}
*

@@ -8,0 +8,0 @@ * @param event Triggering event class

@@ -6,3 +6,3 @@ "use strict";

/**
* Define a step in a saga. Related to {@link core.Saga}
* Define a step in a saga. Related to {@link @moirae/core!Saga}
*

@@ -9,0 +9,0 @@ * @param event Triggering event class

@@ -0,1 +1,2 @@

import { InjectorFunction } from "./injector.interface";
declare type CacheType = "memory" | "redis" | "typeorm";

@@ -7,4 +8,5 @@ export interface ICacheConfig {

clear?: boolean;
injector: InjectorFunction;
type: CacheType;
}
export {};

@@ -0,3 +1,4 @@

import { IEventLike } from "./event-like.interface";
import { Respondable } from "./respondable.interface";
export interface ICommand extends Respondable {
export interface ICommand extends Pick<Respondable, "$executionDomain">, IEventLike {
/**

@@ -4,0 +5,0 @@ * UUID related to a single "transaction" within the system, passed

import { ModuleMetadata, Provider } from "@nestjs/common";
import { ClassConstructor } from "class-transformer";
import { ICacheConfig } from "./cache-config.interface";
import { IPublisherConfig } from "./publisher-config.interface";
import { IPublisherConfig, IPublisherMeta } from "./publisher-config.interface";
import { IStoreConfig } from "./store-config.interface";
export interface IMoiraeConfig<TCache extends ICacheConfig, TPub extends IPublisherConfig, TStore extends IStoreConfig> extends Pick<ModuleMetadata, "imports"> {
export interface IMoiraeConfig<TCache extends ICacheConfig, TStore extends IStoreConfig, TCommand extends IPublisherConfig, TEvent extends IPublisherConfig, TQuery extends IPublisherConfig> extends Pick<ModuleMetadata, "imports"> {
/**

@@ -17,5 +17,11 @@ * Cache provides a storage mechanism internal to Moirae for rapid

/**
* Publisher provides messaging and communication for Commands and Queries
* Publisher provides messaging and communication for Commands, Events, and Queries. This
* can be specialized for each distribution type, having a different publisher configuration
* for each of Commands, Events, and Queries.
*/
publisher?: TPub;
publisher?: IPublisherMeta & {
command: TCommand;
event: TEvent;
query: TQuery;
};
sagas?: Provider[];

@@ -22,0 +28,0 @@ /**

@@ -0,3 +1,8 @@

import { InjectorFunction } from "./injector.interface";
export declare type PublisherType = "memory" | "rabbitmq";
export interface IPublisherConfig {
injector: InjectorFunction;
type: PublisherType;
}
export interface IPublisherMeta {
/**

@@ -14,3 +19,2 @@ * In the case of a microservice system, define the domain token for this

nodeId: string;
type: PublisherType;
}
import { ResponseWrapper } from "../classes/response.class";
import { PublisherRole } from "../moirae.constants";
import { PublisherToken } from "../moirae.constants";
import { IEventLike } from "./event-like.interface";

@@ -9,2 +9,3 @@ /**

export interface IPublisher<Evt = IEventLike> {
domain: string;
/**

@@ -27,3 +28,3 @@ * Await the response from a remote system

*/
role: PublisherRole;
role: PublisherToken;
/**

@@ -30,0 +31,0 @@ * Subscribe to the bus. Should only be called ONCE by the relevant

@@ -5,2 +5,7 @@ /**

*/
export declare type IRequestMetadata = Record<string, unknown>;
export interface IRequestMetadata extends Record<string, unknown> {
/**
* Field to link a specific initiating request to a client
*/
requestorId?: string;
}

@@ -0,5 +1,7 @@

import { InjectorFunction } from "./injector.interface";
declare type StoreType = "memory" | "typeorm";
export interface IStoreConfig {
injector: InjectorFunction;
type: StoreType;
}
export {};

@@ -5,13 +5,17 @@ export declare const APPLY_METADATA = "__apply_event_metadata__";

export declare const COMMAND_METADATA = "__command_handler__";
export declare const COMMAND_PUBLISHER = "__command_publisher__";
export declare const CORRELATION_PREFIX = "moirae__correlation";
export declare const EVENT_METADATA = "__event_handler__";
export declare const EVENT_PUBSUB_ENGINE = "__event-pubsub-engine__";
export declare const EVENT_PUBLISHER = "__event_publisher__";
export declare const EVENT_SOURCE = "__event_source__";
export declare const EXCEPTION_METADATA = "__command_filter__";
export declare const MANAGER = "__manager__";
export declare const PROJECTION_METADATA = "__aggregate_projection__";
export declare const PUBLISHER = "__publisher__";
export declare const PUBLISHER_OPTIONS = "__publisher-options__";
export declare const QUERY_METADATA = "__query_handler__";
export declare const QUERY_PUBLISHER = "__query_publisher__";
export declare const ROLLBACK_METADATA = "__rollback-event-metadata__";
export declare const SAGA_METADATA = "__saga_handler__";
export declare type PublisherToken = typeof COMMAND_PUBLISHER | typeof EVENT_PUBLISHER | typeof QUERY_PUBLISHER;
/**

@@ -18,0 +22,0 @@ * @internal

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PublisherRole = exports.ESState = exports.SAGA_METADATA = exports.ROLLBACK_METADATA = exports.QUERY_METADATA = exports.PUBLISHER_OPTIONS = exports.PUBLISHER = exports.PROJECTION_METADATA = exports.MANAGER = exports.EVENT_SOURCE = exports.EVENT_PUBSUB_ENGINE = exports.EVENT_METADATA = exports.CORRELATION_PREFIX = exports.COMMAND_METADATA = exports.CACHE_PROVIDER = exports.CACHE_OPTIONS = exports.APPLY_METADATA = void 0;
exports.PublisherRole = exports.ESState = exports.SAGA_METADATA = exports.ROLLBACK_METADATA = exports.QUERY_PUBLISHER = exports.QUERY_METADATA = exports.PUBLISHER_OPTIONS = exports.PROJECTION_METADATA = exports.MANAGER = exports.EXCEPTION_METADATA = exports.EVENT_SOURCE = exports.EVENT_PUBLISHER = exports.EVENT_PUBSUB_ENGINE = exports.EVENT_METADATA = exports.CORRELATION_PREFIX = exports.COMMAND_PUBLISHER = exports.COMMAND_METADATA = exports.CACHE_PROVIDER = exports.CACHE_OPTIONS = exports.APPLY_METADATA = void 0;
exports.APPLY_METADATA = "__apply_event_metadata__";

@@ -8,11 +8,14 @@ exports.CACHE_OPTIONS = "__cache-options__";

exports.COMMAND_METADATA = "__command_handler__";
exports.COMMAND_PUBLISHER = "__command_publisher__";
exports.CORRELATION_PREFIX = "moirae__correlation";
exports.EVENT_METADATA = "__event_handler__";
exports.EVENT_PUBSUB_ENGINE = "__event-pubsub-engine__";
exports.EVENT_PUBLISHER = "__event_publisher__";
exports.EVENT_SOURCE = "__event_source__";
exports.EXCEPTION_METADATA = "__command_filter__";
exports.MANAGER = "__manager__";
exports.PROJECTION_METADATA = "__aggregate_projection__";
exports.PUBLISHER = "__publisher__";
exports.PUBLISHER_OPTIONS = "__publisher-options__";
exports.QUERY_METADATA = "__query_handler__";
exports.QUERY_PUBLISHER = "__query_publisher__";
exports.ROLLBACK_METADATA = "__rollback-event-metadata__";

@@ -19,0 +22,0 @@ exports.SAGA_METADATA = "__saga_handler__";

@@ -10,3 +10,3 @@ import { DynamicModule } from "@nestjs/common";

export declare class MoiraeModule {
static forRootAsync<TCache extends ICacheConfig = IMemoryCacheConfig, TPub extends IPublisherConfig = IMemoryPublisherConfig, TStore extends IStoreConfig = IMemoryStoreConfig>(config?: IMoiraeConfig<TCache, TPub, TStore>): Promise<DynamicModule>;
static forRootAsync<TCache extends ICacheConfig = IMemoryCacheConfig, TStore extends IStoreConfig = IMemoryStoreConfig, TCommand extends IPublisherConfig = IMemoryPublisherConfig, TEvent extends IPublisherConfig = IMemoryPublisherConfig, TQuery extends IPublisherConfig = IMemoryPublisherConfig>(config?: IMoiraeConfig<TCache, TStore, TCommand, TEvent, TQuery>): Promise<DynamicModule>;
}

@@ -27,8 +27,57 @@ "use strict";

static async forRootAsync(config = {}) {
const memoryCacheInjector = () => {
return {
exports: [],
providers: [
{
provide: moirae_constants_1.CACHE_PROVIDER,
useClass: memory_cache_1.MemoryCache,
},
],
};
};
const memoryPublisherInjector = (token) => {
return {
exports: [],
providers: [
{
provide: token,
useClass: memory_publisher_1.MemoryPublisher,
},
{
provide: moirae_constants_1.EVENT_PUBSUB_ENGINE,
inject: [observable_factory_1.ObservableFactory],
useFactory: (factory) => factory.generateDistributor((0, crypto_1.randomUUID)()),
},
],
};
};
const memoryStoreInjector = () => ({
exports: [],
providers: [
{
provide: moirae_constants_1.EVENT_SOURCE,
useClass: memory_store_1.MemoryStore,
},
],
});
const { cache = {
injector: memoryCacheInjector,
type: "memory",
}, externalTypes = [], publisher = {
command: {
injector: memoryPublisherInjector,
type: "memory",
},
domain: "default",
type: "memory",
event: {
injector: memoryPublisherInjector,
type: "memory",
},
query: {
injector: memoryPublisherInjector,
type: "memory",
},
}, sagas = [], store = {
injector: memoryStoreInjector,
type: "memory",

@@ -50,64 +99,7 @@ }, imports, } = config;

const exports = [moirae_constants_1.PUBLISHER_OPTIONS, moirae_constants_1.EVENT_PUBSUB_ENGINE];
// Configure the cache providers
switch (cache.type) {
case "redis":
const { RedisCache, RedisConnection } = await Promise.resolve().then(() => require("@moirae/redis"));
providers.push(RedisConnection, {
provide: moirae_constants_1.CACHE_PROVIDER,
useClass: RedisCache,
});
exports.push(RedisConnection);
break;
case "typeorm":
const { TypeORMCache } = await Promise.resolve().then(() => require("@moirae/typeorm"));
providers.push({
provide: moirae_constants_1.CACHE_PROVIDER,
useClass: TypeORMCache,
});
break;
default:
providers.push({
provide: moirae_constants_1.CACHE_PROVIDER,
useClass: memory_cache_1.MemoryCache,
});
}
// Configure the publisher providers
switch (publisher.type) {
case "rabbitmq":
const { RabbitMQConnection, RabbitMQPublisher, RabbitPubSubEngine } = await Promise.resolve().then(() => require("@moirae/rabbitmq"));
providers.push(RabbitMQConnection, {
provide: moirae_constants_1.EVENT_PUBSUB_ENGINE,
useClass: RabbitPubSubEngine,
}, {
provide: moirae_constants_1.PUBLISHER,
useClass: RabbitMQPublisher,
});
exports.push(RabbitMQConnection);
break;
default:
providers.push({
provide: moirae_constants_1.PUBLISHER,
useClass: memory_publisher_1.MemoryPublisher,
}, {
provide: moirae_constants_1.EVENT_PUBSUB_ENGINE,
inject: [observable_factory_1.ObservableFactory],
useFactory: (factory) => factory.generateDistributor((0, crypto_1.randomUUID)()),
});
}
// Configure the event store providers
switch (store.type) {
case "typeorm":
const { TypeORMStore } = await Promise.resolve().then(() => require("@moirae/typeorm"));
providers.push({
provide: moirae_constants_1.EVENT_SOURCE,
useClass: TypeORMStore,
});
break;
default:
providers.push({
provide: moirae_constants_1.EVENT_SOURCE,
useClass: memory_store_1.MemoryStore,
});
}
// TODO: separate public vs private deps
const { exports: cacheExports, providers: cacheProviders } = (cache.injector || memoryCacheInjector)();
const { exports: commandExports, providers: commandProviders } = (publisher.command.injector || memoryPublisherInjector)(moirae_constants_1.COMMAND_PUBLISHER);
const { exports: eventExports, providers: eventProviders } = (publisher.event.injector || memoryPublisherInjector)(moirae_constants_1.EVENT_PUBLISHER);
const { exports: queryExports, providers: queryProviders } = (publisher.query.injector || memoryPublisherInjector)(moirae_constants_1.QUERY_PUBLISHER);
const { exports: storeExports, providers: storeProviders } = (store.injector || memoryStoreInjector)();
return {

@@ -127,4 +119,20 @@ global: true,

...sagas,
...cacheProviders,
...commandProviders,
...eventProviders,
...queryProviders,
...storeProviders,
],
exports: [aggregate_factory_1.AggregateFactory, command_bus_1.CommandBus, event_bus_1.EventBus, query_bus_1.QueryBus, ...exports],
exports: [
aggregate_factory_1.AggregateFactory,
command_bus_1.CommandBus,
event_bus_1.EventBus,
query_bus_1.QueryBus,
...exports,
...cacheExports,
...commandExports,
...eventExports,
...queryExports,
...storeExports,
],
};

@@ -131,0 +139,0 @@ }

import { BasePublisher } from "../classes/base.publisher";
import { ObservableFactory } from "../factories/observable.factory";
import { IEventLike } from "../interfaces/event-like.interface";
import { IPublisherConfig } from "../interfaces/publisher-config.interface";
import { IPublisherMeta } from "../interfaces/publisher-config.interface";
import { IPublisher } from "../interfaces/publisher.interface";
export declare class MemoryPublisher<Evt extends IEventLike> extends BasePublisher<Evt> implements IPublisher {
private _queue;
constructor(observableFactory: ObservableFactory, publisherOptions: IPublisherConfig);
constructor(observableFactory: ObservableFactory, publisherOptions: IPublisherMeta);
private advanceBus;

@@ -10,0 +10,0 @@ protected handleAcknowledge(event: Evt): Promise<void>;

import { ObservableFactory } from "../factories/observable.factory";
import { IEventSource } from "../interfaces/event-source.interface";
import { IEvent } from "../interfaces/event.interface";
import { IPublisherConfig } from "../interfaces/publisher-config.interface";
import { IPublisherMeta } from "../interfaces/publisher-config.interface";
import { MemoryPublisher } from "../publishers/memory.publisher";
export declare class MemoryStore extends MemoryPublisher<IEvent> implements IEventSource {
private _streams;
constructor(observableFactory: ObservableFactory, publisherOptions: IPublisherConfig);
constructor(observableFactory: ObservableFactory, publisherOptions: IPublisherMeta);
appendToStream(eventList: IEvent[]): Promise<IEvent[]>;

@@ -10,0 +10,0 @@ onApplicationBootstrap(): Promise<void>;

@@ -23,3 +23,3 @@ "use strict";

super(observableFactory, publisherOptions);
this.role = moirae_constants_1.PublisherRole.EVENT_STORE;
this.role = moirae_constants_1.EVENT_PUBLISHER;
}

@@ -26,0 +26,0 @@ async appendToStream(eventList) {

{
"name": "@moirae/core",
"packageManager": "yarn@3.2.0",
"main": "dist/index.js",
"version": "0.4.2",
"version": "0.5.3",
"license": "MIT",

@@ -10,3 +9,3 @@ "repository": {

"url": "https://github.com/chance-get-yours/moirae",
"directory": "packages/core"
"directory": "moirae/core"
},

@@ -21,32 +20,35 @@ "engines": {

"peerDependencies": {
"@nestjs/common": "^8.4.7",
"@nestjs/core": "^8.4.7",
"@nestjs/common": "^9.1.4",
"@nestjs/core": "^9.1.4",
"reflect-metadata": "^0.1.13"
},
"dependencies": {
"class-transformer": "^0.5.1",
"class-transformer": "~0.5.1",
"object-hash": "^3.0.0"
},
"devDependencies": {
"@faker-js/faker": "^6.3.1",
"@nestjs/common": "^8.4.7",
"@nestjs/core": "^8.4.7",
"@nestjs/testing": "^8.4.7",
"@swc/core": "^1.2.205",
"@swc/jest": "^0.2.21",
"@types/jest": "^28.1.1",
"@types/node": "^17.0.31",
"@faker-js/faker": "~7.6.0",
"@nestjs/common": "~9.1.6",
"@nestjs/core": "~9.1.6",
"@nestjs/testing": "~9.1.6",
"@swc/core": "1.2.205",
"@swc/jest": "^0.2.23",
"@types/node": "18.8.4",
"@types/object-hash": "^2.2.1",
"jest": "^28.1.1",
"@types/jest": "~29.2.0",
"jest": "~29.2.2",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^7.5.5",
"typescript": "^4.6.4"
"rimraf": "~3.0.2",
"rxjs": "^7.5.7",
"typescript": "~4.8.4"
},
"scripts": {
"build": "yarn prebuild && tsc",
"build": "npm run prebuild && tsc -p tsconfig.build.json",
"prebuild": "rimraf ./dist",
"pack": "npm pack",
"test": "env JEST_ROOT_DIR=core jest --config=../../jest.config.js"
},
"typedoc": {
"readmeFile": "./README.md"
}
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc