UNPKG

@dolittle/sdk.aggregates

Version:

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

40 lines 3.12 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.AggregateRootsModelBuilder = void 0; const AggregateRootTypes_1 = require("../AggregateRootTypes"); const AggregateRootModelId_1 = require("../AggregateRootModelId"); const IAggregateOf_1 = require("../IAggregateOf"); const IAggregates_1 = require("./IAggregates"); /** * Represents a builder that can build {@link IAggregateRootTypes} from an {@link IModel}. */ class AggregateRootsModelBuilder { /** * Initialises a new instance of the {@link AggregateRootsModelBuilder} class. * @param {IModel} _model - The built application model. * @param {IServiceProviderBuilder} _bindings - For registering the bindings for {@link IAggregateOf} types. */ constructor(_model, _bindings) { this._model = _model; this._bindings = _bindings; } /** * Builds an {@link IAggregateRootTypes} from the associated and registered aggregate root types. * @returns {IAggregateRootTypes} The built event types. */ build() { const bindings = this._model.getTypeBindings(AggregateRootModelId_1.isAggregateRootModelId); const aggregateRootTypes = new AggregateRootTypes_1.AggregateRootTypes(); for (const { identifier, type } of bindings) { aggregateRootTypes.associate(type, identifier.aggregateRootType); this._bindings.addTenantServices(binder => { binder.bind(IAggregateOf_1.IAggregateOf.for(type)).toFactory(services => services.get(IAggregates_1.IAggregates).of(type)); }); } return aggregateRootTypes; } } exports.AggregateRootsModelBuilder = AggregateRootsModelBuilder; //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQWdncmVnYXRlUm9vdHNNb2RlbEJ1aWxkZXIuanMiLCJzb3VyY2VSb290IjoiLi4vIiwic291cmNlcyI6WyJCdWlsZGVycy9BZ2dyZWdhdGVSb290c01vZGVsQnVpbGRlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsK0NBQStDO0FBQy9DLHFHQUFxRzs7O0FBS3JHLDhEQUEyRDtBQUMzRCxrRUFBa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