UNPKG

@microsoft/dev-tunnels-ssh

Version:
46 lines 1.76 kB
"use strict"; // // Copyright (c) Microsoft Corporation. All rights reserved. // Object.defineProperty(exports, "__esModule", { value: true }); exports.findService = exports.serviceActivation = void 0; /** * Decorator applied to suclasses of `SshService` that declares how the service gets activated. */ function serviceActivation(activation) { // eslint-disable-next-line @typescript-eslint/ban-types return (constructor) => { if (!constructor.activations) { constructor.activations = []; } constructor.activations.push(activation); }; } exports.serviceActivation = serviceActivation; /** * Locates a service type in configuration, using a predicate to check service activation * attributes. * * @param serviceConfigs Service configuration dictionary from `SshSessionConfiguration.services`. * @param predicate Function to test whether a service activation attribute matches some condition. * @returns Service type (constructor), or null if no service type satisfies the predicate. */ function findService(serviceConfigs, predicate) { for (const serviceType of serviceConfigs.keys()) { const activations = serviceType.activations; let foundActivation = false; for (const activation of activations) { foundActivation = true; if (predicate(activation)) { return serviceType; } } if (!foundActivation) { throw new Error(`SSH service type '${serviceType.name}' must have one or more ` + '\'serviceActivation\' decorators.'); } } return null; } exports.findService = findService; //# sourceMappingURL=serviceActivation.js.map