UNPKG

@dolittle/sdk.aggregates

Version:

Dolittle is a decentralized, distributed, event-driven microservice platform built to harness the power of events.

43 lines 3.66 kB
"use strict"; // Copyright (c) Dolittle. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. Object.defineProperty(exports, "__esModule", { value: true }); exports.getDecoratedAggregateRootType = exports.isDecoratedAggregateRootType = exports.aggregateRoot = void 0; const sdk_artifacts_1 = require("@dolittle/sdk.artifacts"); const sdk_common_1 = require("@dolittle/sdk.common"); const sdk_events_1 = require("@dolittle/sdk.events"); const AggregateRootType_1 = require("./AggregateRootType"); const AggregateRootTypeAlias_1 = require("./AggregateRootTypeAlias"); const [decorator, getMetadata] = sdk_common_1.Decorators.createMetadataDecorator('aggregate-root-type', 'aggregateRoot', sdk_common_1.Decorators.DecoratorTarget.Class); /** * Decorator to mark a class as an aggregate root. * @param {AggregateRootIdLike} aggregateRootId - The identifier of the aggregate root. * @param {AggregateRootTypeOptions} [options={}] - Options to give to the aggregate root. * @returns {Decorators.Decorator} The decorator. */ function aggregateRoot(aggregateRootId, options = {}) { return decorator((target, type) => { var _a; return new AggregateRootType_1.AggregateRootType(sdk_events_1.AggregateRootId.from(aggregateRootId), sdk_artifacts_1.Generation.first, AggregateRootTypeAlias_1.AggregateRootTypeAlias.from((_a = options.alias) !== null && _a !== void 0 ? _a : type.name)); }); } exports.aggregateRoot = aggregateRoot; /** * Checks whether the specified class is decorated with an aggregate root type. * @param {Constructor<any>} type - The class to check the decorated aggregate root type for. * @returns {boolean} True if the decorator is applied, false if not. */ function isDecoratedAggregateRootType(type) { return getMetadata(type, false, false) !== undefined; } exports.isDecoratedAggregateRootType = isDecoratedAggregateRootType; /** * Gets the decorated aggregate root type of the specified class. * @param {Constructor<any>} type - The class to get the decorated aggregate root type for. * @returns {AggregateRootType} The decorated aggregate root type. */ function getDecoratedAggregateRootType(type) { return getMetadata(type, true, 'Classes used as aggregate roots must be decorated'); } exports.getDecoratedAggregateRootType = getDecoratedAggregateRootType; //#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