UNPKG

the-wireguard-effect

Version:

Cross platform wireguard api client for nodejs built on wireguard-go with effect-ts

25 lines 1.42 kB
import * as NodeSocket from "@effect/platform-node/NodeSocket"; import * as Chunk from "effect/Chunk"; import * as Effect from "effect/Effect"; import * as Function from "effect/Function"; import * as Option from "effect/Option"; import * as Schema from "effect/Schema"; import * as Sink from "effect/Sink"; import * as Stream from "effect/Stream"; import * as String from "effect/String"; import * as WireguardErrors from "../WireguardErrors.js"; /** @internal */ export const SupportedArchitectures = ["x64", "arm64"]; /** @internal */ export const SupportedPlatforms = ["linux", "darwin", "win32"]; /** @internal */ export const LinuxInterfaceNameRegExp = /^wg\d+$/; /** @internal */ export const DarwinInterfaceNameRegExp = /^utun\d+$/; /** @internal */ export const WindowsInterfaceNameRegExp = /^eth\d+$/; /** @internal */ export const userspaceContact = (wireguardInterface, content) => Function.pipe(Stream.make(content), Stream.pipeThroughChannelOrFail(NodeSocket.makeNetChannel({ path: wireguardInterface.SocketLocation })), Stream.decodeText(), Stream.flatMap(Function.compose(String.linesIterator, Stream.fromIterable)), Stream.map(String.trimEnd), Stream.filter(String.isNonEmpty), Stream.run(Sink.collectAll()), Effect.tap(Function.flow(Chunk.last, Option.getOrThrow, Schema.decodeUnknown(WireguardErrors.SuccessErrno))), Effect.map(Chunk.join("\n"))); //# sourceMappingURL=wireguardInterface.js.map