UNPKG

@dolittle/sdk.execution

Version:

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

70 lines 4.8 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.ExecutionContext = void 0; const TenantId_1 = require("./TenantId"); const CorrelationId_1 = require("./CorrelationId"); /** * Represents the execution context in a running application. */ class ExecutionContext { /** * Creates an instance of execution context. * @param {MicroserviceId}_microserviceId - The microservice identifier. * @param {TenantId} _tenantId - The current tenant identifier. * @param {Version} version - The current version of the software. * @param {string} environment - The current environment running in. * @param {CorrelationId} _correlationId - The current correlation id for execution context being performed. * @param {Claims} claims - The current claims for the context. */ constructor(_microserviceId, _tenantId, version, environment, _correlationId, claims) { this._microserviceId = _microserviceId; this._tenantId = _tenantId; this.version = version; this.environment = environment; this._correlationId = _correlationId; this.claims = claims; } /** * Gets the microservice identifier. */ get microserviceId() { return this._microserviceId; } /** * Gets the tenant identifier. */ get tenantId() { return this._tenantId; } /** * Gets the correlation identifier. */ get correlationId() { return this._correlationId; } /** * Creates a new execution context from the current with the provided tenant id. * @param {TenantId | Guid | string} tenantId - The tenant id. * @returns {ExecutionContext} The new execution context. */ forTenant(tenantId) { return new ExecutionContext(this.microserviceId, TenantId_1.TenantId.from(tenantId), this.version, this.environment, this.correlationId, this.claims); } ; /** * Creates a new execution context from the current with the provided correlation id. * @param {CorrelationId | Guid | string} correlationId - The correlation id. * @returns {ExecutionContext} The new execution context. */ forCorrelation(correlationId) { return new ExecutionContext(this.microserviceId, this.tenantId, this.version, this.environment, CorrelationId_1.CorrelationId.from(correlationId), this.claims); } ; /** * Creates a new execution context from the current with the provided claims. * @param {Claims} claims - The claims. * @returns {ExecutionContext} The new execution context. */ forClaims(claims) { return new ExecutionContext(this.microserviceId, this.tenantId, this.version, this.environment, this.correlationId, claims); } ; } exports.ExecutionContext = ExecutionContext; //# sourceMappingURL=data:application/json;base64,eyJ2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