@gjsify/net 0.30.0 → 0.31.0

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.
@@ -1,2 +1,2 @@
1
- import"./_virtual/_rolldown/runtime.js";const e=`browser`;function callerFrame(e){if(!e)return;let t=[];for(let n of e.split(`
2
- `).slice(1)){let e=n.trim();if(e&&!(e.includes(`unsupported`)||e.includes(`callerFrame`))&&(t.push(e.replace(/^at\s+/,``)),t.length===2))break}return t[1]??t[0]}function unsupported(t){let n=callerFrame(Error().stack),r=Error(`[@gjsify/net/${e}] net.${t} is not available on the ${e} platform: a browser sandbox exposes no raw TCP — it can neither dial an arbitrary host:port nor accept an inbound connection.${n?` Called from ${n}.`:``}`);throw r.code=`ENOTSUP`,r.errno=-45,r.syscall=t,r.gjsifyModule=`net`,r.gjsifyRuntime=e,n!==void 0&&(r.gjsifyImporter=n),r}function isIP(e){if(typeof e!=`string`)return 0;let t=e.includes(`%`)?e.slice(0,e.indexOf(`%`)):e,n=/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec(t);if(n)return n.slice(1).every(e=>(e.length===1||e[0]!==`0`)&&Number(e)<=255)?4:0;if(t.length===0||!t.includes(`:`))return 0;let r=/:(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/.exec(t),i=r?t.slice(0,t.length-r[1].length):t;if(r&&isIP(r[1])!==4)return 0;let a=i.split(`::`);if(a.length>2)return 0;let o=[];for(let e of a)for(let t of e.split(`:`))if(t!==``){if(!/^[0-9a-fA-F]{1,4}$/.test(t))return 0;o.push(t)}let s=r?6:8;return a.length===2?o.length<s?6:0:o.length===s?6:0}function isIPv4(e){return isIP(e)===4}function isIPv6(e){return isIP(e)===6}var Socket=class{constructor(){unsupported(`Socket`)}},Server=class{constructor(){unsupported(`Server`)}};function createConnection(...e){return unsupported(`createConnection`)}function connect(...e){return unsupported(`connect`)}function createServer(...e){return unsupported(`createServer`)}const t={isIP,isIPv4,isIPv6,Socket,Server,createConnection,connect,createServer};export{Server,Socket,connect,createConnection,createServer,t as default,isIP,isIPv4,isIPv6};
1
+ import"./_virtual/_rolldown/runtime.js";import{isIP as e,isIPv4 as t,isIPv6 as n}from"./is-ip.js";const r=`browser`;function callerFrame(e){if(!e)return;let t=[];for(let n of e.split(`
2
+ `).slice(1)){let e=n.trim();if(e&&!(e.includes(`unsupported`)||e.includes(`callerFrame`))&&(t.push(e.replace(/^at\s+/,``)),t.length===2))break}return t[1]??t[0]}function unsupported(e){let t=callerFrame(Error().stack),n=Error(`[@gjsify/net/${r}] net.${e} is not available on the ${r} platform: a browser sandbox exposes no raw TCP — it can neither dial an arbitrary host:port nor accept an inbound connection.${t?` Called from ${t}.`:``}`);throw n.code=`ENOTSUP`,n.errno=-45,n.syscall=e,n.gjsifyModule=`net`,n.gjsifyRuntime=r,t!==void 0&&(n.gjsifyImporter=t),n}var Socket=class{constructor(){unsupported(`Socket`)}},Server=class{constructor(){unsupported(`Server`)}};function createConnection(...e){return unsupported(`createConnection`)}function connect(...e){return unsupported(`connect`)}function createServer(...e){return unsupported(`createServer`)}const i={isIP:e,isIPv4:t,isIPv6:n,Socket,Server,createConnection,connect,createServer};export{Server,Socket,connect,createConnection,createServer,i as default,e as isIP,t as isIPv4,n as isIPv6};
package/lib/esm/index.js CHANGED
@@ -1 +1 @@
1
- import"./_virtual/_rolldown/runtime.js";import{Socket as e}from"./socket.js";import{Server as t}from"./server.js";import n from"@girs/gio-2.0";function isIP(e){if(typeof e!=`string`)return 0;let t=e.includes(`%`)?e.split(`%`)[0]:e,r=n.InetAddress.new_from_string(t);if(!r)return 0;switch(r.get_family()){case n.SocketFamily.INVALID:return 0;case n.SocketFamily.IPV4:return 4;case n.SocketFamily.IPV6:return 6}}function isIPv4(e){return isIP(e)===4}function isIPv6(e){return isIP(e)===6}function createConnection(t,n,r){return new e().connect(t,n,r)}const r=createConnection;function createServer(e,n){return typeof e==`function`?new t(e):new t(e,n)}var i={Socket:e,Server:t,isIP,isIPv4,isIPv6,createConnection,connect:r,createServer};export{t as Server,e as Socket,r as connect,createConnection,createServer,i as default,isIP,isIPv4,isIPv6};
1
+ import"./_virtual/_rolldown/runtime.js";import{isIP as e,isIPv4 as t,isIPv6 as n}from"./is-ip.js";import{Socket as r}from"./socket.js";import{Server as i}from"./server.js";function createConnection(e,t,n){return new r().connect(e,t,n)}const a=createConnection;function createServer(e,t){return typeof e==`function`?new i(e):new i(e,t)}var o={Socket:r,Server:i,isIP:e,isIPv4:t,isIPv6:n,createConnection,connect:a,createServer};export{i as Server,r as Socket,a as connect,createConnection,createServer,o as default,e as isIP,t as isIPv4,n as isIPv6};
@@ -0,0 +1 @@
1
+ import"./_virtual/_rolldown/runtime.js";function isIP(e){if(typeof e!=`string`)return 0;let t=e.includes(`%`)?e.slice(0,e.indexOf(`%`)):e,n=/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec(t);if(n)return n.slice(1).every(e=>(e.length===1||e[0]!==`0`)&&Number(e)<=255)?4:0;if(t.length===0||!t.includes(`:`))return 0;let r=/:(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/.exec(t),i=r?t.slice(0,t.length-r[0].length):t;if(r&&isIP(r[1])!==4)return 0;let a=i.split(`::`);if(a.length>2)return 0;let o=0;for(let e of a)if(e!==``)for(let t of e.split(`:`)){if(!/^[0-9a-fA-F]{1,4}$/.test(t))return 0;o++}let s=r?6:8;return a.length===2?o<s?6:0:o===s?6:0}function isIPv4(e){return isIP(e)===4}function isIPv6(e){return isIP(e)===6}export{isIP,isIPv4,isIPv6};
@@ -1,15 +1,5 @@
1
- /**
2
- * Check whether `input` is a valid IP address. Returns 0 (no), 4 or 6.
3
- *
4
- * Pure string classification — identical answer on every runtime. The GJS root
5
- * entry routes this through `Gio.InetAddress`; here it is the coarse regex
6
- * classifier, matching what `@gjsify/dns`'s browser entry inlines.
7
- */
8
- export declare function isIP(input: string): 0 | 4 | 6;
9
- /** Check whether `input` is a valid IPv4 address. */
10
- export declare function isIPv4(input: string): boolean;
11
- /** Check whether `input` is a valid IPv6 address. */
12
- export declare function isIPv6(input: string): boolean;
1
+ export { isIP, isIPv4, isIPv6 } from './is-ip.js';
2
+ import { isIP, isIPv4, isIPv6 } from './is-ip.js';
13
3
  /** A TCP client socket. Constructing one needs raw TCP; throws `ENOTSUP`. */
14
4
  export declare class Socket {
15
5
  constructor();
@@ -2,12 +2,8 @@ export { Socket, type SocketConnectOptions } from './socket.js';
2
2
  export { Server, type ListenOptions } from './server.js';
3
3
  import { Socket, type SocketConnectOptions } from './socket.js';
4
4
  import { Server } from './server.js';
5
- /** Check if input is a valid IP address. Returns 0, 4, or 6. */
6
- export declare function isIP(input: string): 0 | 4 | 6;
7
- /** Check if input is a valid IPv4 address. */
8
- export declare function isIPv4(input: string): boolean;
9
- /** Check if input is a valid IPv6 address. */
10
- export declare function isIPv6(input: string): boolean;
5
+ export { isIP, isIPv4, isIPv6 } from './is-ip.js';
6
+ import { isIP, isIPv4, isIPv6 } from './is-ip.js';
11
7
  /** Create a new TCP connection. */
12
8
  export declare function createConnection(options: SocketConnectOptions | number, host?: string | (() => void), connectionListener?: () => void): Socket;
13
9
  /** Alias for createConnection. */
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Classify `input` as an IP address: `0` (no), `4` (IPv4) or `6` (IPv6).
3
+ *
4
+ * Matches Node's answer, including the parts that are easy to get wrong:
5
+ * leading zeros in an IPv4 octet are rejected, an IPv6 zone id (`fe80::1%en0`)
6
+ * is not part of the address proper, at most one `::` run is allowed, and an
7
+ * IPv4-mapped tail (`::ffff:127.0.0.1`) must itself be a valid IPv4 address.
8
+ */
9
+ export declare function isIP(input: string): 0 | 4 | 6;
10
+ /** Check whether `input` is a valid IPv4 address. */
11
+ export declare function isIPv4(input: string): boolean;
12
+ /** Check whether `input` is a valid IPv6 address. */
13
+ export declare function isIPv6(input: string): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/net",
3
- "version": "0.30.0",
3
+ "version": "0.31.0",
4
4
  "description": "Node.js net module for Gjs",
5
5
  "type": "module",
6
6
  "module": "lib/esm/index.js",
@@ -41,18 +41,18 @@
41
41
  "net"
42
42
  ],
43
43
  "devDependencies": {
44
- "@gjsify/cli": "^0.30.0",
45
- "@gjsify/unit": "^0.30.0",
44
+ "@gjsify/cli": "^0.31.0",
45
+ "@gjsify/unit": "^0.31.0",
46
46
  "@types/node": "^25.9.2",
47
47
  "typescript": "^6.0.3"
48
48
  },
49
49
  "dependencies": {
50
50
  "@girs/gio-2.0": "^4.1.0",
51
51
  "@girs/glib-2.0": "^4.1.0",
52
- "@gjsify/buffer": "^0.30.0",
53
- "@gjsify/events": "^0.30.0",
54
- "@gjsify/stream": "^0.30.0",
55
- "@gjsify/utils": "^0.30.0"
52
+ "@gjsify/buffer": "^0.31.0",
53
+ "@gjsify/events": "^0.31.0",
54
+ "@gjsify/stream": "^0.31.0",
55
+ "@gjsify/utils": "^0.31.0"
56
56
  },
57
57
  "gjsify": {
58
58
  "runtimes": {