@solidrt/flux-types 0.0.13 → 0.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -5,6 +5,8 @@
5
5
  /// <reference path="./modules/sqlite.d.ts" />
6
6
  /// <reference path="./modules/subprocess.d.ts" />
7
7
  /// <reference path="./modules/p2p.d.ts" />
8
+ /// <reference path="./modules/net.d.ts" />
9
+ /// <reference path="./modules/mdns.d.ts" />
8
10
 
9
11
  // Web-standard globals. The runtime is QuickJS, not a browser or Node, so it
10
12
  // ships no lib.dom / @types/bun: these declarations are the sole source for
@@ -0,0 +1,54 @@
1
+ declare module "flux:mdns" {
2
+ /** Options common to {@link resolve}, {@link browse}, and {@link services}. */
3
+ type MdnsOptions = {
4
+ /** How long (ms) to collect multicast answers before resolving. Default 1500. */
5
+ timeoutMs?: number
6
+ }
7
+
8
+ /** A reverse-resolved address, from {@link resolve}. */
9
+ type Resolved = {
10
+ /** The queried IPv4 address. */
11
+ ip: string
12
+ /** Its mDNS hostname, e.g. "printer.local". */
13
+ host: string
14
+ }
15
+
16
+ /** One discovered DNS-SD service instance, from {@link browse}. */
17
+ type ServiceInstance = {
18
+ /** The human instance label, e.g. "Office Printer". */
19
+ instance: string
20
+ /** The service type, e.g. "_ipp._tcp". */
21
+ service: string
22
+ /** The target host the SRV record points at, e.g. "printer.local". */
23
+ host: string
24
+ /** The advertised port. */
25
+ port: number
26
+ /** A/AAAA addresses for `host`, when the responder bundled them. */
27
+ addrs: string[]
28
+ /** TXT attributes (a bare flag attribute has an empty-string value). */
29
+ txt: Record<string, string>
30
+ }
31
+
32
+ /**
33
+ * Reverse-resolve IPv4 addresses to their mDNS `.local` hostnames over the
34
+ * link-local multicast group (a PTR query against `in-addr.arpa`). `.local`
35
+ * names are mDNS, not unicast DNS, so this works with no `nss-mdns` resolver and
36
+ * no external binary. Addresses that do not answer within the window — and any
37
+ * IPv6 inputs — are simply absent from the result; an empty input resolves to
38
+ * `[]` without touching the network. Needs a Bonjour/avahi responder on the LAN.
39
+ */
40
+ export function resolve(ips: string[], opts?: MdnsOptions): Promise<Resolved[]>
41
+
42
+ /**
43
+ * Browse a DNS-SD service type for the instances on the LAN. `service` may be
44
+ * bare (`"_http._tcp"`) or fully qualified. Resolves to `[]` if nothing answers
45
+ * within the window.
46
+ */
47
+ export function browse(service: string, opts?: MdnsOptions): Promise<ServiceInstance[]>
48
+
49
+ /**
50
+ * Enumerate the service types advertised on the LAN (the
51
+ * `_services._dns-sd._udp.local` meta-query), e.g. `["_http._tcp", "_ipp._tcp"]`.
52
+ */
53
+ export function services(opts?: MdnsOptions): Promise<string[]>
54
+ }
@@ -0,0 +1,139 @@
1
+ declare module "flux:net" {
2
+ /** Options for {@link probe} and {@link connect}. */
3
+ type ConnectOptions = {
4
+ /** Give up after this many ms. Default 1000 for {@link probe}, 10000 for {@link connect}. */
5
+ timeoutMs?: number
6
+ }
7
+
8
+ /** Options for {@link listen}. */
9
+ type ListenOptions = {
10
+ /** Local address to bind. Default "0.0.0.0" (all interfaces). */
11
+ host?: string
12
+ }
13
+
14
+ /** Options for {@link udp}. */
15
+ type UdpOptions = {
16
+ /** Local port to bind. Default 0 (OS-assigned). */
17
+ port?: number
18
+ /** Set SO_REUSEADDR/REUSEPORT so several sockets can share the port. */
19
+ reuse?: boolean
20
+ }
21
+
22
+ /**
23
+ * Outcome of a {@link probe}. `closed` (a refusal) still means the host is up —
24
+ * something answered; only `filtered` (a timeout/unreachable) is no evidence.
25
+ */
26
+ type Liveness = "open" | "closed" | "filtered"
27
+
28
+ /** One address on a {@link NetInterface}. */
29
+ type InterfaceAddr = {
30
+ /** The IP address. */
31
+ ip: string
32
+ /** CIDR prefix length (e.g. 24). */
33
+ prefix: number
34
+ /** Address family. */
35
+ family: "v4" | "v6"
36
+ }
37
+
38
+ /** A local network interface, from {@link interfaces}. */
39
+ type NetInterface = {
40
+ /** Interface name, e.g. "wlan0". */
41
+ name: string
42
+ /** Hardware (MAC) address, or `null` if none. */
43
+ mac: string | null
44
+ /** Whether the interface is up. */
45
+ up: boolean
46
+ /** Whether it is a loopback interface. */
47
+ loopback: boolean
48
+ /** Whether it supports multicast. */
49
+ multicast: boolean
50
+ /** The interface's bound addresses. */
51
+ addrs: InterfaceAddr[]
52
+ }
53
+
54
+ /** A received datagram, from {@link Udp.recv}. */
55
+ type Datagram = {
56
+ /** The payload bytes. */
57
+ data: Uint8Array
58
+ /** Sender IP. */
59
+ host: string
60
+ /** Sender port. */
61
+ port: number
62
+ }
63
+
64
+ /**
65
+ * A connected TCP stream: a byte duplex. It is its own async iterator, so
66
+ * `for await (let chunk of conn)` reads it until end-of-stream.
67
+ */
68
+ export class Conn implements AsyncIterable<Uint8Array> {
69
+ /** The remote peer's address, e.g. "192.168.2.37:445". */
70
+ readonly peer: string
71
+ /** Write all of `data`. Resolves once it is handed to the OS. */
72
+ write(data: string | Uint8Array): Promise<void>
73
+ /** Stop reading and close the connection. */
74
+ close(): void
75
+ [Symbol.asyncIterator](): AsyncIterator<Uint8Array>
76
+ }
77
+
78
+ /**
79
+ * A bound TCP listener: an async-iterable of incoming connections, so
80
+ * `for await (let conn of listener)` accepts them. Drop it to stop.
81
+ */
82
+ export class Listener implements AsyncIterable<Conn> {
83
+ /** The bound local address (with the OS-assigned port when 0 was requested). */
84
+ readonly localAddr: string
85
+ [Symbol.asyncIterator](): AsyncIterator<Conn>
86
+ }
87
+
88
+ /** A bound UDP socket with the broadcast/multicast controls a peer beacon needs. */
89
+ export class Udp {
90
+ /** The bound local address (with the OS-assigned port when 0 was requested). */
91
+ readonly localAddr: string
92
+ /** Send a datagram to `host:port` — a unicast peer, a broadcast address, or a multicast group. */
93
+ send(data: string | Uint8Array, host: string, port: number): Promise<void>
94
+ /** Receive the next datagram. */
95
+ recv(): Promise<Datagram>
96
+ /** Allow sending to the broadcast address (SO_BROADCAST). */
97
+ setBroadcast(on: boolean): void
98
+ /** TTL for outgoing multicast (1 keeps it on the local link). */
99
+ setMulticastTtl(ttl: number): void
100
+ /** Whether multicast this socket sends loops back to sockets on this host. */
101
+ setMulticastLoop(on: boolean): void
102
+ /**
103
+ * Join multicast `group` on the interface with address `iface`
104
+ * (default "0.0.0.0", OS-chosen). Required to receive that group's datagrams.
105
+ */
106
+ joinMulticast(group: string, iface?: string): void
107
+ /** Leave a multicast group previously joined with {@link joinMulticast}. */
108
+ leaveMulticast(group: string, iface?: string): void
109
+ }
110
+
111
+ /**
112
+ * Probe `host:port` with a TCP connect and report what it says about the host.
113
+ * Infallible — every outcome maps to a {@link Liveness}, so a sweep never has to
114
+ * catch. The connect-scan primitive: count `open` or `closed` as a live host.
115
+ *
116
+ * @param opts timeoutMs (default 1000).
117
+ */
118
+ export function probe(host: string, port: number, opts?: ConnectOptions): Promise<Liveness>
119
+
120
+ /**
121
+ * Open a TCP connection. Unlike {@link probe} this returns a live {@link Conn}
122
+ * for app protocols / banner grabs.
123
+ *
124
+ * @param opts timeoutMs (default 10000).
125
+ */
126
+ export function connect(host: string, port: number, opts?: ConnectOptions): Promise<Conn>
127
+
128
+ /** Bind a TCP {@link Listener} on `port` (0 = OS-assigned). */
129
+ export function listen(port: number, opts?: ListenOptions): Promise<Listener>
130
+
131
+ /** Bind a {@link Udp} socket. */
132
+ export function udp(opts?: UdpOptions): Promise<Udp>
133
+
134
+ /**
135
+ * Enumerate local network interfaces and their addresses — the no-subprocess
136
+ * way to find the subnet to scan (replaces parsing `ip addr`). Synchronous.
137
+ */
138
+ export function interfaces(): NetInterface[]
139
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidrt/flux-types",
3
- "version": "0.0.13",
3
+ "version": "0.0.16",
4
4
  "license": "MIT",
5
5
  "author": "Antoine van Wel",
6
6
  "types": "index.d.ts",