/** * Pure, canonical IPv4 and IPv6 network prefixes using CIDR notation. * * @stability unstable * @since 4.0.0 */ import * as Equal from "../Equal.ts"; import * as Hash from "../Hash.ts"; import * as Inspectable from "../Inspectable.ts"; import * as Result from "../Result.ts"; import * as IpInterface from "./IpInterface.ts"; import * as NetAddress from "./NetAddress.ts"; declare const TypeId: "~effect/net/IpNetwork"; /** * An immutable canonical IP network prefix. Constructors that retain the exact * input address also retain its verified refinements. Operations that derive a * different address return only its IPv4 or IPv6 family; revalidate the result * before treating it as refined. * * @stability unstable * @category models * @since 4.0.0 */ export interface IpNetwork extends Equal.Equal, Hash.Hash, Inspectable.Inspectable { readonly _tag: "IpNetwork"; readonly address: A; readonly prefixLength: number; readonly [TypeId]: typeof TypeId; } /** * An immutable canonical IPv4 network prefix. * * @stability unstable * @category models * @since 4.0.0 */ export type Ipv4Network = IpNetwork; /** * An immutable canonical IPv6 network prefix. * * @stability unstable * @category models * @since 4.0.0 */ export type Ipv6Network = IpNetwork; /** * A network address and prefix length, generic over the accepted address * input. The address must have no host bits set. * * @see {@link make} for the checked constructor * @stability unstable * @category models * @since 4.0.0 */ export type IpNetworkParts = IpInterface.IpInterfaceParts; /** * An IP network prefix, or a CIDR string or parts to convert to one. * * @stability unstable * @category models * @since 4.0.0 */ export type IpNetworkInput = IpNetwork | string | IpNetworkParts; /** * An IPv4 network prefix, or a CIDR string or parts to convert to one. * * @stability unstable * @category models * @since 4.0.0 */ export type Ipv4NetworkInput = Ipv4Network | string | IpNetworkParts; /** * An IPv6 network prefix, or a CIDR string or parts to convert to one. * * @stability unstable * @category models * @since 4.0.0 */ export type Ipv6NetworkInput = Ipv6Network | string | IpNetworkParts; /** * Returns `true` when a value is an IPv4 network prefix. * * @stability unstable * @category guards * @since 4.0.0 */ export declare const isIpv4Network: (u: unknown) => u is Ipv4Network; /** * Returns `true` when a value is an IPv6 network prefix. * * @stability unstable * @category guards * @since 4.0.0 */ export declare const isIpv6Network: (u: unknown) => u is Ipv6Network; /** * Returns `true` when a value is an IPv4 or IPv6 network prefix. * * @stability unstable * @category guards * @since 4.0.0 */ export declare const isIpNetwork: (u: unknown) => u is IpNetwork; /** * Creates a network prefix when the address has no host bits set. * * **Gotchas** * * Use {@link fromAddress} when a host address should be truncated to its containing network. * * @stability unstable * @category constructors * @since 4.0.0 */ export declare const make: (address: A, prefixLength: number) => Result.Result, NetAddress.NetAddressError>; /** * Creates the canonical network containing an address by clearing its host bits. * * **Gotchas** * * The returned network's address can differ from the input address. * Its type therefore retains the IPv4 or IPv6 family but not refinements on * the input address. Revalidate the derived address to recover a refinement. * * @stability unstable * @category constructors * @since 4.0.0 */ export declare const fromAddress: (address: A, prefixLength: number) => Result.Result>, NetAddress.NetAddressError>; /** * Returns the canonical network containing an interface address. The derived * address retains its IPv4 or IPv6 family but not refinements on the input. * * @stability unstable * @category conversions * @since 4.0.0 */ export declare const fromInterface: (self: IpInterface.IpInterface) => IpNetwork>; /** * Parses a strict IPv4 network prefix in CIDR notation. * * @stability unstable * @category decoding * @since 4.0.0 */ export declare const ipv4FromString: (input: string) => Result.Result; /** * Parses a strict IPv6 network prefix in CIDR notation. * * @stability unstable * @category decoding * @since 4.0.0 */ export declare const ipv6FromString: (input: string) => Result.Result; /** * Parses a strict IPv4 or IPv6 network prefix in CIDR notation. * * @stability unstable * @category decoding * @since 4.0.0 */ export declare const fromString: (input: string) => Result.Result; /** * Converts an `Ipv4NetworkInput` to an IPv4 network prefix, parsing strings * like `ipv4FromString`, converting parts like `make`, and returning network * prefixes unchanged. * * @stability unstable * @category constructors * @since 4.0.0 */ export declare const ipv4FromInput: (input: Ipv4NetworkInput) => Result.Result; /** * Converts an `Ipv6NetworkInput` to an IPv6 network prefix, parsing strings * like `ipv6FromString`, converting parts like `make`, and returning network * prefixes unchanged. * * @stability unstable * @category constructors * @since 4.0.0 */ export declare const ipv6FromInput: (input: Ipv6NetworkInput) => Result.Result; /** * Converts an `IpNetworkInput` to a network prefix, parsing strings like * `fromString`, converting parts like `make`, and returning network prefixes * unchanged. * * **Gotchas** * * Like `make`, an address with host bits set is rejected rather than truncated. * * @stability unstable * @category constructors * @since 4.0.0 */ export declare const fromInput: (input: IpNetworkInput) => Result.Result; /** * Converts a trusted `IpNetworkInput` to a network prefix, throwing on failure. * * @stability unstable * @category unsafe * @since 4.0.0 */ export declare const fromInputUnsafe: (input: IpNetworkInput) => IpNetwork; /** * Creates a trusted network prefix, throwing when its address or prefix is invalid. * * @stability unstable * @category unsafe * @since 4.0.0 */ export declare const makeUnsafe: (address: A, prefixLength: number) => IpNetwork; /** * Creates the network containing a trusted address, throwing when its prefix is invalid. * The derived address retains its IPv4 or IPv6 family but not refinements on * the input address. * * @stability unstable * @category unsafe * @since 4.0.0 */ export declare const fromAddressUnsafe: (address: A, prefixLength: number) => IpNetwork>; /** * Parses a trusted network prefix in CIDR notation, throwing on failure. * * @stability unstable * @category unsafe * @since 4.0.0 */ export declare const fromStringUnsafe: (input: string) => IpNetwork; /** * Formats a network prefix using canonical address text and its decimal prefix length. * * @stability unstable * @category encoding * @since 4.0.0 */ export declare const format: (self: IpNetwork) => string; /** * Returns the lowest address in a network prefix. * * @stability unstable * @category getters * @since 4.0.0 */ export declare const firstAddress: (self: IpNetwork) => A; /** * Returns the numerically greatest address in a network prefix. The derived * address retains its IPv4 or IPv6 family but not refinements on the network * address. * * @stability unstable * @category getters * @since 4.0.0 */ export declare const lastAddress: (self: IpNetwork) => NetAddress.Family; /** * Returns the exact number of addresses in a network prefix. * * @stability unstable * @category getters * @since 4.0.0 */ export declare const addressCount: (self: IpNetwork) => bigint; /** * Returns `true` when a network prefix contains an IP address. * * @stability unstable * @category predicates * @since 4.0.0 */ export declare const contains: { /** * Returns `true` when a network prefix contains an IP address. * * @stability unstable * @category predicates * @since 4.0.0 */ (address: NetAddress.IpAddress): (self: IpNetwork) => boolean; /** * Returns `true` when a network prefix contains an IP address. * * @stability unstable * @category predicates * @since 4.0.0 */ (self: IpNetwork, address: NetAddress.IpAddress): boolean; }; /** * Returns `true` when a network prefix contains every address in another network prefix. * * @stability unstable * @category predicates * @since 4.0.0 */ export declare const containsNetwork: { /** * Returns `true` when a network prefix contains every address in another network prefix. * * @stability unstable * @category predicates * @since 4.0.0 */ (other: IpNetwork): (self: IpNetwork) => boolean; /** * Returns `true` when a network prefix contains every address in another network prefix. * * @stability unstable * @category predicates * @since 4.0.0 */ (self: IpNetwork, other: IpNetwork): boolean; }; /** * Returns `true` when two network prefixes contain at least one common address. * * @stability unstable * @category predicates * @since 4.0.0 */ export declare const overlaps: { /** * Returns `true` when two network prefixes contain at least one common address. * * @stability unstable * @category predicates * @since 4.0.0 */ (other: IpNetwork): (self: IpNetwork) => boolean; /** * Returns `true` when two network prefixes contain at least one common address. * * @stability unstable * @category predicates * @since 4.0.0 */ (self: IpNetwork, other: IpNetwork): boolean; }; export {}; //# sourceMappingURL=IpNetwork.d.ts.map