UNPKG

the-moby-effect

Version:
93 lines 3.09 kB
/** * Operating system port schema. * * @since 1.0.0 */ import * as Brand from "effect/Brand"; import * as Function from "effect/Function"; import * as Schema from "effect/Schema"; /** * @since 1.0.0 * @category Branded constructors */ export const PortBrand = /*#__PURE__*/Brand.nominal(); /** * An operating system port number. * * @since 1.0.0 * @category Schemas * @example * import * as Schema from "effect/Schema"; * import { Port } from "the-moby-effect/schemas/index.js"; * * const decodePort = Schema.decodeSync(Port); * assert.strictEqual(decodePort(8080), 8080); * * assert.throws(() => decodePort(65536)); * assert.doesNotThrow(() => decodePort(8080)); */ export const Port = /*#__PURE__*/Function.pipe(Schema.Int, /*#__PURE__*/Schema.between(0, 2 ** 16 - 1), /*#__PURE__*/Schema.fromBrand(PortBrand), /*#__PURE__*/Schema.annotations({ identifier: "Port", title: "An OS port number", description: "An operating system's port number between 0 and 65535 (inclusive)" })); /** * An operating system port number with an optional protocol. * * @since 1.0.0 * @category Schemas */ export const PortWithMaybeProtocol = /*#__PURE__*/Schema.Union(Schema.TemplateLiteral(Schema.Number), Schema.TemplateLiteral(Schema.Number, "/", Schema.Literal("tcp")), Schema.TemplateLiteral(Schema.Number, "/", Schema.Literal("udp"))).annotations({ identifier: "PortWithMaybeProtocol", title: "An OS port number with an optional protocol", description: "An operating system's port number with an optional protocol" }); /** * A set of operating system ports. * * @since 1.0.0 * @category Schemas * @see https://github.com/docker/go-connections/blob/5df8d2b30ca886f2d94740ce3c54abd58a5bb2c9/nat/nat.go#L23 */ export const PortSet = /*#__PURE__*/Schema.Record({ key: PortWithMaybeProtocol, // FIXME: What is this type? value: Schema.Object }).annotations({ identifier: "PortSet", title: "A set of OS ports", description: "A set of operating system ports" }); /** * A port binding between the exposed port (container) and the host. * * @since 1.0.0 * @category Schemas * @see https://github.com/docker/go-connections/blob/5df8d2b30ca886f2d94740ce3c54abd58a5bb2c9/nat/nat.go#L11-L17 */ export const PortBinding = /*#__PURE__*/Schema.Struct({ HostPort: Schema.String, HostIp: Schema.optionalWith(Schema.String, { nullable: true }) }).annotations({ identifier: "PortBinding", title: "nat.PortBinding", description: "A port binding between the exposed port (container) and the host" }); /** * Port mapping between the exposed port (container) and the host. * * @since 1.0.0 * @category Schemas * @see https://github.com/docker/go-connections/blob/5df8d2b30ca886f2d94740ce3c54abd58a5bb2c9/nat/nat.go#L20 */ export const PortMap = /*#__PURE__*/Schema.Record({ key: PortWithMaybeProtocol, value: Schema.Array(PortBinding) }).annotations({ identifier: "PortMap", title: "nat.PortMap", description: "Port mapping between the exposed port (container) and the host" }); //# sourceMappingURL=port.js.map