@gjsify/net 0.23.0 → 0.24.1
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/lib/esm/browser.js +2 -0
- package/lib/types/browser.d.ts +34 -0
- package/package.json +11 -7
|
@@ -0,0 +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};
|
|
@@ -0,0 +1,34 @@
|
|
|
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;
|
|
13
|
+
/** A TCP client socket. Constructing one needs raw TCP; throws `ENOTSUP`. */
|
|
14
|
+
export declare class Socket {
|
|
15
|
+
constructor();
|
|
16
|
+
}
|
|
17
|
+
/** A TCP listening socket. A browser cannot accept connections; throws `ENOTSUP`. */
|
|
18
|
+
export declare class Server {
|
|
19
|
+
constructor();
|
|
20
|
+
}
|
|
21
|
+
export declare function createConnection(..._args: unknown[]): Socket;
|
|
22
|
+
export declare function connect(..._args: unknown[]): Socket;
|
|
23
|
+
export declare function createServer(..._args: unknown[]): Server;
|
|
24
|
+
declare const netDefault: {
|
|
25
|
+
isIP: typeof isIP;
|
|
26
|
+
isIPv4: typeof isIPv4;
|
|
27
|
+
isIPv6: typeof isIPv6;
|
|
28
|
+
Socket: typeof Socket;
|
|
29
|
+
Server: typeof Server;
|
|
30
|
+
createConnection: typeof createConnection;
|
|
31
|
+
connect: typeof connect;
|
|
32
|
+
createServer: typeof createServer;
|
|
33
|
+
};
|
|
34
|
+
export default netDefault;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/net",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.1",
|
|
4
4
|
"description": "Node.js net module for Gjs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "lib/esm/index.js",
|
|
@@ -13,6 +13,10 @@
|
|
|
13
13
|
"./socket": {
|
|
14
14
|
"types": "./lib/types/socket.d.ts",
|
|
15
15
|
"default": "./lib/esm/socket.js"
|
|
16
|
+
},
|
|
17
|
+
"./browser": {
|
|
18
|
+
"types": "./lib/types/browser.d.ts",
|
|
19
|
+
"default": "./lib/esm/browser.js"
|
|
16
20
|
}
|
|
17
21
|
},
|
|
18
22
|
"files": [
|
|
@@ -37,18 +41,18 @@
|
|
|
37
41
|
"net"
|
|
38
42
|
],
|
|
39
43
|
"devDependencies": {
|
|
40
|
-
"@gjsify/cli": "^0.
|
|
41
|
-
"@gjsify/unit": "^0.
|
|
44
|
+
"@gjsify/cli": "^0.24.1",
|
|
45
|
+
"@gjsify/unit": "^0.24.1",
|
|
42
46
|
"@types/node": "^25.9.2",
|
|
43
47
|
"typescript": "^6.0.3"
|
|
44
48
|
},
|
|
45
49
|
"dependencies": {
|
|
46
50
|
"@girs/gio-2.0": "^4.1.0",
|
|
47
51
|
"@girs/glib-2.0": "^4.1.0",
|
|
48
|
-
"@gjsify/buffer": "^0.
|
|
49
|
-
"@gjsify/events": "^0.
|
|
50
|
-
"@gjsify/stream": "^0.
|
|
51
|
-
"@gjsify/utils": "^0.
|
|
52
|
+
"@gjsify/buffer": "^0.24.1",
|
|
53
|
+
"@gjsify/events": "^0.24.1",
|
|
54
|
+
"@gjsify/stream": "^0.24.1",
|
|
55
|
+
"@gjsify/utils": "^0.24.1"
|
|
52
56
|
},
|
|
53
57
|
"gjsify": {
|
|
54
58
|
"runtimes": {
|