UNPKG

@adpt/cloud

Version:
100 lines 3.32 kB
"use strict"; /* * Copyright 2018-2019 Unbounded Systems, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ Object.defineProperty(exports, "__esModule", { value: true }); const core_1 = require("@adpt/core"); /** * Type for various network address scopes * * @remarks * The details of this type are very experimental. Use the constants `NetworkScope.external` * and `NetworkScope.default` instead of strings to reduce the chance of breakage. * * @beta */ var NetworkScope; (function (NetworkScope) { NetworkScope["external"] = "external"; NetworkScope["default"] = "default"; })(NetworkScope = exports.NetworkScope || (exports.NetworkScope = {})); /** * An abstract component that represents a network service. * * @public */ class NetworkService extends core_1.PrimitiveComponent { /** * Returns the hostname of the NetworkService, once it is known. */ hostname(scope) { const hand = this.props.handle; if (!hand) throw new Error(`Internal error: Element props.handle is null`); return core_1.callNextInstanceMethod(hand, undefined, "hostname", scope); } /** * Returns the port number of the NetworkService, once it is known. */ port() { const hand = this.props.handle; if (!hand) throw new Error(`Internal error: Element props.handle is null`); return core_1.callNextInstanceMethod(hand, undefined, "port"); } } NetworkService.defaultProps = { protocol: "TCP", scope: "cluster-internal", }; exports.NetworkService = NetworkService; exports.default = NetworkService; /** * Computes the target port that will be used for a NetworkService * * @param elemOrProps - a {@link NetworkService} element or its props * @returns The target port of the {@link NetworkService} object * * @public */ function targetPort(elemOrProps) { let props = elemOrProps; if (core_1.isElement(elemOrProps)) props = elemOrProps.props; if (props.targetPort) return props.targetPort; if (props.port) return props.port; throw new Error(`Cannot compute target port for props ${props}`); } exports.targetPort = targetPort; /** * Type assertion that tests an element to see if it is a {@link NetworkService} * * @param el - the element to be tested * @returns `true` if `el` is a NetworkService, `false` otherwise * * @remarks * Also functions as a type assertion for Typescript, so the arguments * type will be adjusted to reflect that it is an `AdaptElement<NetworkServiceProps>` * instead of a generic `AdaptElement`. * * @public */ function isNetworkServiceElement(el) { return el.componentType === NetworkService; } exports.isNetworkServiceElement = isNetworkServiceElement; //# sourceMappingURL=NetworkService.js.map