UNPKG

the-moby-effect

Version:
173 lines 4.7 kB
/** * IPv6 address schema. * * @since 1.0.0 */ import * as Brand from "effect/Brand"; import * as Schema from "effect/Schema"; /** * @since 1.0.0 * @category Regular expressions * @see https://github.com/nodejs/node/blob/e08a654fae0ecc91678819e0b62a2e014bad3339/lib/internal/net.js#L21-L31 */ export declare const IPv6Segment = "(?:[0-9a-fA-F]{1,4})"; /** * @since 1.0.0 * @category Regular expressions */ export declare const IPv6Regex: RegExp; /** * @since 1.0.0 * @category Api interface */ export interface $IPv6Family extends Schema.Literal<["ipv6"]> { } /** * @since 1.0.0 * @category Decoded types */ export type IPv6Family = Schema.Schema.Type<$IPv6Family>; /** * @since 1.0.0 * @category Schemas */ export declare const IPv6Family: $IPv6Family; /** * @since 1.0.0 * @category Api interface */ export interface $IPv6String extends Schema.filter<Schema.Schema<string, string, never>> { } /** * An IPv6 address in string format. * * @since 1.0.0 * @category Schemas */ export declare const IPv6String: $IPv6String; /** * @since 1.0.0 * @category Branded types */ export type IPv6Brand = string & Brand.Brand<"IPv6">; /** * @since 1.0.0 * @category Branded constructors */ export declare const IPv6Brand: Brand.Brand.Constructor<IPv6Brand>; /** * @since 1.0.0 * @category Api interface */ export interface $IPv6 extends Schema.transform<Schema.filter<Schema.Schema<string, string, never>>, Schema.Struct<{ family: $IPv6Family; ip: Schema.BrandSchema<IPv6Brand, Brand.Brand.Unbranded<IPv6Brand>, never>; }>> { } /** * @since 1.0.0 * @category Decoded types */ export type IPv6 = Schema.Schema.Type<$IPv6>; /** * @since 1.0.0 * @category Encoded types */ export type IPv6Encoded = Schema.Schema.Encoded<$IPv6>; /** * An IPv6 address. * * @since 1.0.0 * @category Schemas * @example * import * as Schema from "effect/Schema"; * import { IPv6 } from "the-moby-effect/schemas/index.js"; * * const decodeIPv6 = Schema.decodeSync(IPv6); * assert.deepEqual(decodeIPv6("2001:0db8:85a3:0000:0000:8a2e:0370:7334"), { * family: "ipv6", * ip: "2001:0db8:85a3:0000:0000:8a2e:0370:7334", * }); * * assert.throws(() => * decodeIPv6("2001:0db8:85a3:0000:0000:8a2e:0370:7334:") * ); * assert.throws(() => decodeIPv6("2001::85a3::0000::0370:7334")); * assert.doesNotThrow(() => * decodeIPv6("2001:0db8:85a3:0000:0000:8a2e:0370:7334") * ); */ export declare const IPv6: $IPv6; /** * @since 1.0.0 * @category Branded types */ export type IPv6BigintBrand = bigint & Brand.Brand<"IPv6Bigint">; /** * @since 1.0.0 * @category Branded constructors */ export declare const IPv6BigintBrand: Brand.Brand.Constructor<IPv6BigintBrand>; /** * @since 1.0.0 * @category Api interface */ export interface $IPv6Bigint extends Schema.transformOrFail<$IPv6, Schema.Struct<{ family: $IPv6Family; value: Schema.BrandSchema<IPv6BigintBrand, Brand.Brand.Unbranded<IPv6BigintBrand>, never>; }>, never> { } /** * @since 1.0.0 * @category Decoded types */ export type IPv6Bigint = Schema.Schema.Type<$IPv6Bigint>; /** * @since 1.0.0 * @category Encoded types */ export type IPv6BigintEncoded = Schema.Schema.Encoded<$IPv6Bigint>; /** * An IPv6 as a bigint. * * @since 1.0.0 * @category Schemas * @example * import * as Schema from "effect/Schema"; * import { * IPv6Bigint, * IPv6BigintBrand, * } from "the-moby-effect/schemas/IPv6.js"; * * const y: IPv6BigintBrand = IPv6BigintBrand(748392749382n); * assert.strictEqual(y, 748392749382n); * * const decodeIPv6Bigint = Schema.decodeSync(IPv6Bigint); * const encodeIPv6Bigint = Schema.encodeSync(IPv6Bigint); * * assert.deepEqual( * decodeIPv6Bigint("4cbd:ff70:e62b:a048:686c:4e7e:a68a:c377"), * { value: 102007852745154114519525620108359287671n, family: "ipv6" } * ); * assert.deepEqual( * decodeIPv6Bigint("d8c6:3feb:46e6:b80c:5a07:6227:ac19:caf6"), * { value: 288142618299897818094313964584331496182n, family: "ipv6" } * ); * * assert.deepEqual( * encodeIPv6Bigint({ * value: IPv6BigintBrand(102007852745154114519525620108359287671n), * family: "ipv6", * }), * "4cbd:ff70:e62b:a048:686c:4e7e:a68a:c377" * ); * assert.deepEqual( * encodeIPv6Bigint({ * value: IPv6BigintBrand(288142618299897818094313964584331496182n), * family: "ipv6", * }), * "d8c6:3feb:46e6:b80c:5a07:6227:ac19:caf6" * ); */ export declare const IPv6Bigint: $IPv6Bigint; //# sourceMappingURL=ipv6.d.ts.map