UNPKG

@dolittle/sdk.aggregates

Version:

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

60 lines 4.3 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.isAggregateRootType = exports.AggregateRootType = void 0; const sdk_artifacts_1 = require("@dolittle/sdk.artifacts"); const sdk_events_1 = require("@dolittle/sdk.events"); const AggregateRootTypeAlias_1 = require("./AggregateRootTypeAlias"); /** * Represents the type of an aggregate root. */ class AggregateRootType extends sdk_artifacts_1.Artifact { /** * Initializes a new instance of {@link EventType}. * @param {AggregateRootType} id - The unique identifier of the aggregate root type. * @param {Generation} [generation = Generation.first] - Optional generation - will default to {@link generation.first}. * @param {AggregateRootTypeAlias} [alias = undefined] - Optional alias. */ constructor(id, generation = sdk_artifacts_1.Generation.first, alias) { super(id, generation); this.alias = alias; } /** * Gets a value indicating whether there is an alias for the aggregate root type. * @returns {boolean} A value indicating whether there is an alias for the aggregate root type. */ hasAlias() { return this.alias !== undefined; } /** @inheritdoc */ toString() { return `AggregateRootType(${this.id}, ${this.generation})`; } /** * Creates an instance of {@link AggregateRootType}. * @param {AggregateRootIdLike} id - The aggregate root type id. * @param {GenerationLike | undefined} generation - The optional generation of the aggregate root type. * @returns {AggregateRootType} The created aggregate root type. */ static from(id, generation) { if (generation === undefined) { generation = sdk_artifacts_1.Generation.first; } return new AggregateRootType(sdk_events_1.AggregateRootId.from(id), sdk_artifacts_1.Generation.from(generation)); } } exports.AggregateRootType = AggregateRootType; /** * Checks whether or not an object is an instance of {@link AggregateRootType}. * @param {any} object - The object to check. * @returns {boolean} True if the object is an {@link AggregateRootType}, false if not. */ exports.isAggregateRootType = (0, sdk_artifacts_1.createIsArtifact)(AggregateRootType, sdk_events_1.isAggregateRootId, (type) => { if (type.alias !== undefined && !(0, AggregateRootTypeAlias_1.isAggregateRootTypeAlias)(type.alias)) return false; if (typeof type.hasAlias !== 'function' || type.hasAlias.length !== 0) return false; return true; }); //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQWdncmVnYXRlUm9vdFR5cGUuanMiLCJzb3VyY2VSb290IjoiLi4vIiwic291cmNlcyI6WyJBZ2dyZWdhdGVSb290VHlwZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsK0NBQStDO0FBQy9DLHFHQUFxRzs7O0FBRXJHLDJEQUFpRztBQUNqRyxxREFBK0Y7QUFFL0YscUVBQTRGO0FBRTVGOztHQUVHO0FBQ0gsTUFBYSxpQkFBa0IsU0FBUSx3QkFBeUI7SUFDNUQ7Ozs7O09BS0c7SUFDSCxZQUFZLEVBQW1CLEVBQUUsYUFBeUIsMEJBQVUsQ0FBQyxLQUFLLEVBQVcsS0FBOEI7UUFDL0csS0FBSyxDQUFDLEVBQUUsRUFBRSxVQUFVLENBQUMsQ0FBQztRQUQyRCxVQUFLLEdBQUwsS0FBSyxDQUF5QjtJQUVuSCxDQUFDO0lBRUQ7OztPQUdHO0lBQ0gsUUFBUTtRQUNKLE9BQU8sSUFBSSxDQUFDLEtBQUssS0FBSyxTQUFTLENBQUM7SUFDcEMsQ0FBQztJQUVELGtCQUFrQjtJQUNsQixRQUFRO1FBQ0osT0FBTyxxQkFBcUIsSUFBSSxDQUFDLEVBQUUsS0FBSyxJQUFJLENBQUMsVUFBVSxHQUFHLENBQUM7SUFDL0QsQ0FBQztJQUVEOzs7OztPQUtHO0lBQ0gsTUFBTSxDQUFDLElBQUksQ0FBQyxFQUF1QixFQUFFLFVBQTJCO1FBQzVELElBQUksVUFBVSxLQUFLLFNBQVMsRUFBRTtZQUMxQixVQUFVLEdBQUcsMEJBQVUsQ0FBQyxLQUFLLENBQUM7U0FDakM7UUFFRCxPQUFPLElBQUksaUJBQWlCLENBQUMsNEJBQWUsQ0FBQyxJQUFJLENBQUMsRUFBRSxDQUFDLEVBQUUsMEJBQVUsQ0FBQyxJQUFJL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