UNPKG

@dolittle/sdk.resources

Version:

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

56 lines 3.33 kB
import { Logger } from 'winston'; import { ExecutionContext, TenantId } from '@dolittle/sdk.execution'; import { Cancellation } from '@dolittle/sdk.resilience'; import { UnaryMethod } from '@dolittle/sdk.services'; import { Failure } from '@dolittle/contracts/Protobuf/Failure_pb'; import { CallRequestContext } from '@dolittle/contracts/Services/CallContext_pb'; import { ResourcesClient } from '@dolittle/contracts/Runtime/Resources/Resources_grpc_pb'; import { ResourceName } from '../ResourceName'; /** * Represents a system that can create resources by fetching configuration from the Runtime. * @template TResource - The type of the resource. * @template TRequest - The type of the resource configuration request. * @template TResponse - The type of the resource configuration response. */ export declare abstract class ResourceCreator<TResource, TRequest, TResponse> { private readonly _resource; private readonly _method; private readonly _client; private readonly _executionContext; private readonly _logger; /** * Initialises a new instance of the {@link ResourceCreator} class. * @param {ResourceName} _resource - The name of the resource type. * @param {UnaryMethod} _method - The gRPC method to call to get the resource configuration from the Runtime. * @param {ResourcesClient} _client - The resources client to make requests to the Runtime with. * @param {ExecutionContext} _executionContext - The base execution context for the client. * @param {Logger} _logger - The logger to use for logging. */ protected constructor(_resource: ResourceName, _method: UnaryMethod<TRequest, TResponse>, _client: ResourcesClient, _executionContext: ExecutionContext, _logger: Logger); /** * Creates the resource for the provided tenant by fetching configuration from the Runtime. * @param {TenantId} tenant - The tenant id to create the resource for. * @param {Cancellation} cancellation - An optional cancellation to cancel the operation. * @returns {Promise} - A {@link Promise} that, when resolved, returns the created resource. */ createFor(tenant: TenantId, cancellation?: Cancellation): Promise<TResource>; /** * Creates a request to get the resource configuration using the provided call context. * @param {CallRequestContext} callContext - The call context to use for the request containing the tenant id. * @returns {TRequest} A new request. */ protected abstract createResourceRequest(callContext: CallRequestContext): TRequest; /** * Checks whether the request failed based on the response. * @param {TResponse} response - The response received from the Runtime. * @returns {[false] | [true, Failure]} False if the request succeeded, true and the failure if it failed. */ protected abstract requestFailed(response: TResponse): [false] | [true, Failure]; /** * Creates the resource from the configuration received from the Runtime. * @param {TResponse} response - The response received from the Runtime. * @returns {Promise<TResource>} - A {@link Promise} that, when resolved, returns the created resource. */ protected abstract createResourceFrom(response: TResponse): Promise<TResource>; } //# sourceMappingURL=ResourceCreator.d.ts.map