@robinpath/cli 1.73.0 → 1.75.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.
- package/README.md +111 -111
- package/dist/cli.mjs +344 -301
- package/modules/_helpers.js +33 -33
- package/modules/assert.js +270 -270
- package/modules/buffer.js +245 -245
- package/modules/child.js +176 -176
- package/modules/crypto.js +352 -352
- package/modules/dns.js +146 -146
- package/modules/events.js +174 -174
- package/modules/file.js +361 -361
- package/modules/http.js +268 -268
- package/modules/index.js +76 -76
- package/modules/net.js +189 -189
- package/modules/os.js +219 -219
- package/modules/path.js +162 -162
- package/modules/process.js +214 -214
- package/modules/stream.js +322 -322
- package/modules/string_decoder.js +106 -106
- package/modules/timer.js +167 -167
- package/modules/tls.js +264 -264
- package/modules/tty.js +169 -169
- package/modules/url.js +189 -189
- package/modules/util.js +275 -275
- package/modules/zlib.js +126 -126
- package/package.json +1 -1
package/modules/index.js
CHANGED
|
@@ -1,76 +1,76 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* RobinPath Native Modules — Barrel Export
|
|
3
|
-
* All modules listed here are bundled into the CLI binary.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
// Phase 1: Core System
|
|
7
|
-
import FileModule from './file.js';
|
|
8
|
-
import PathModule from './path.js';
|
|
9
|
-
import ProcessModule from './process.js';
|
|
10
|
-
import OsModule from './os.js';
|
|
11
|
-
|
|
12
|
-
// Phase 2: Data & Security
|
|
13
|
-
import CryptoModule from './crypto.js';
|
|
14
|
-
import BufferModule from './buffer.js';
|
|
15
|
-
import UrlModule from './url.js';
|
|
16
|
-
import ChildModule from './child.js';
|
|
17
|
-
import TimerModule from './timer.js';
|
|
18
|
-
|
|
19
|
-
// Phase 3a: Networking & I/O
|
|
20
|
-
import HttpModule from './http.js';
|
|
21
|
-
import NetModule from './net.js';
|
|
22
|
-
import DnsModule from './dns.js';
|
|
23
|
-
import EventsModule from './events.js';
|
|
24
|
-
import ZlibModule from './zlib.js';
|
|
25
|
-
|
|
26
|
-
// Phase 3b: Streams, TLS & Utilities
|
|
27
|
-
import StreamModule from './stream.js';
|
|
28
|
-
import TlsModule from './tls.js';
|
|
29
|
-
import UtilModule from './util.js';
|
|
30
|
-
import AssertModule from './assert.js';
|
|
31
|
-
import StringDecoderModule from './string_decoder.js';
|
|
32
|
-
import TtyModule from './tty.js';
|
|
33
|
-
|
|
34
|
-
// Phase 4: Document & Format Generation (uncomment as implemented)
|
|
35
|
-
// import ArchiveModule from './archive.js';
|
|
36
|
-
// import EmailModule from './email.js';
|
|
37
|
-
// import BarcodeModule from './barcode.js';
|
|
38
|
-
// import PdfModule from './pdf.js';
|
|
39
|
-
// import ExcelModule from './excel.js';
|
|
40
|
-
|
|
41
|
-
export const nativeModules = [
|
|
42
|
-
// Phase 1: Core System
|
|
43
|
-
FileModule,
|
|
44
|
-
PathModule,
|
|
45
|
-
ProcessModule,
|
|
46
|
-
OsModule,
|
|
47
|
-
|
|
48
|
-
// Phase 2: Data & Security
|
|
49
|
-
CryptoModule,
|
|
50
|
-
BufferModule,
|
|
51
|
-
UrlModule,
|
|
52
|
-
ChildModule,
|
|
53
|
-
TimerModule,
|
|
54
|
-
|
|
55
|
-
// Phase 3a: Networking & I/O
|
|
56
|
-
HttpModule,
|
|
57
|
-
NetModule,
|
|
58
|
-
DnsModule,
|
|
59
|
-
EventsModule,
|
|
60
|
-
ZlibModule,
|
|
61
|
-
|
|
62
|
-
// Phase 3b: Streams, TLS & Utilities
|
|
63
|
-
StreamModule,
|
|
64
|
-
TlsModule,
|
|
65
|
-
UtilModule,
|
|
66
|
-
AssertModule,
|
|
67
|
-
StringDecoderModule,
|
|
68
|
-
TtyModule,
|
|
69
|
-
|
|
70
|
-
// Phase 4
|
|
71
|
-
// ArchiveModule,
|
|
72
|
-
// EmailModule,
|
|
73
|
-
// BarcodeModule,
|
|
74
|
-
// PdfModule,
|
|
75
|
-
// ExcelModule,
|
|
76
|
-
];
|
|
1
|
+
/**
|
|
2
|
+
* RobinPath Native Modules — Barrel Export
|
|
3
|
+
* All modules listed here are bundled into the CLI binary.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// Phase 1: Core System
|
|
7
|
+
import FileModule from './file.js';
|
|
8
|
+
import PathModule from './path.js';
|
|
9
|
+
import ProcessModule from './process.js';
|
|
10
|
+
import OsModule from './os.js';
|
|
11
|
+
|
|
12
|
+
// Phase 2: Data & Security
|
|
13
|
+
import CryptoModule from './crypto.js';
|
|
14
|
+
import BufferModule from './buffer.js';
|
|
15
|
+
import UrlModule from './url.js';
|
|
16
|
+
import ChildModule from './child.js';
|
|
17
|
+
import TimerModule from './timer.js';
|
|
18
|
+
|
|
19
|
+
// Phase 3a: Networking & I/O
|
|
20
|
+
import HttpModule from './http.js';
|
|
21
|
+
import NetModule from './net.js';
|
|
22
|
+
import DnsModule from './dns.js';
|
|
23
|
+
import EventsModule from './events.js';
|
|
24
|
+
import ZlibModule from './zlib.js';
|
|
25
|
+
|
|
26
|
+
// Phase 3b: Streams, TLS & Utilities
|
|
27
|
+
import StreamModule from './stream.js';
|
|
28
|
+
import TlsModule from './tls.js';
|
|
29
|
+
import UtilModule from './util.js';
|
|
30
|
+
import AssertModule from './assert.js';
|
|
31
|
+
import StringDecoderModule from './string_decoder.js';
|
|
32
|
+
import TtyModule from './tty.js';
|
|
33
|
+
|
|
34
|
+
// Phase 4: Document & Format Generation (uncomment as implemented)
|
|
35
|
+
// import ArchiveModule from './archive.js';
|
|
36
|
+
// import EmailModule from './email.js';
|
|
37
|
+
// import BarcodeModule from './barcode.js';
|
|
38
|
+
// import PdfModule from './pdf.js';
|
|
39
|
+
// import ExcelModule from './excel.js';
|
|
40
|
+
|
|
41
|
+
export const nativeModules = [
|
|
42
|
+
// Phase 1: Core System
|
|
43
|
+
FileModule,
|
|
44
|
+
PathModule,
|
|
45
|
+
ProcessModule,
|
|
46
|
+
OsModule,
|
|
47
|
+
|
|
48
|
+
// Phase 2: Data & Security
|
|
49
|
+
CryptoModule,
|
|
50
|
+
BufferModule,
|
|
51
|
+
UrlModule,
|
|
52
|
+
ChildModule,
|
|
53
|
+
TimerModule,
|
|
54
|
+
|
|
55
|
+
// Phase 3a: Networking & I/O
|
|
56
|
+
HttpModule,
|
|
57
|
+
NetModule,
|
|
58
|
+
DnsModule,
|
|
59
|
+
EventsModule,
|
|
60
|
+
ZlibModule,
|
|
61
|
+
|
|
62
|
+
// Phase 3b: Streams, TLS & Utilities
|
|
63
|
+
StreamModule,
|
|
64
|
+
TlsModule,
|
|
65
|
+
UtilModule,
|
|
66
|
+
AssertModule,
|
|
67
|
+
StringDecoderModule,
|
|
68
|
+
TtyModule,
|
|
69
|
+
|
|
70
|
+
// Phase 4
|
|
71
|
+
// ArchiveModule,
|
|
72
|
+
// EmailModule,
|
|
73
|
+
// BarcodeModule,
|
|
74
|
+
// PdfModule,
|
|
75
|
+
// ExcelModule,
|
|
76
|
+
];
|
package/modules/net.js
CHANGED
|
@@ -1,189 +1,189 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Native net module for RobinPath.
|
|
3
|
-
* TCP client/server and socket operations.
|
|
4
|
-
*/
|
|
5
|
-
import { createServer, createConnection, isIP, isIPv4, isIPv6 } from 'node:net';
|
|
6
|
-
import { toStr, toNum, requireArgs } from './_helpers.js';
|
|
7
|
-
|
|
8
|
-
const _servers = new Map();
|
|
9
|
-
const _sockets = new Map();
|
|
10
|
-
let _nextId = 1;
|
|
11
|
-
|
|
12
|
-
export const NetFunctions = {
|
|
13
|
-
|
|
14
|
-
connect: (args) => {
|
|
15
|
-
requireArgs('net.connect', args, 2);
|
|
16
|
-
const host = toStr(args[0]);
|
|
17
|
-
const port = toNum(args[1]);
|
|
18
|
-
const id = `sock_${_nextId++}`;
|
|
19
|
-
|
|
20
|
-
return new Promise((resolve, reject) => {
|
|
21
|
-
const socket = createConnection({ host, port }, () => {
|
|
22
|
-
_sockets.set(id, { socket, data: '' });
|
|
23
|
-
socket.on('data', (chunk) => {
|
|
24
|
-
const entry = _sockets.get(id);
|
|
25
|
-
if (entry) entry.data += chunk.toString();
|
|
26
|
-
});
|
|
27
|
-
socket.on('end', () => { _sockets.delete(id); });
|
|
28
|
-
socket.on('error', () => { _sockets.delete(id); });
|
|
29
|
-
resolve(id);
|
|
30
|
-
});
|
|
31
|
-
socket.on('error', (err) => reject(new Error(`net.connect: ${err.message}`)));
|
|
32
|
-
});
|
|
33
|
-
},
|
|
34
|
-
|
|
35
|
-
send: (args) => {
|
|
36
|
-
requireArgs('net.send', args, 2);
|
|
37
|
-
const id = toStr(args[0]);
|
|
38
|
-
const data = toStr(args[1]);
|
|
39
|
-
const entry = _sockets.get(id);
|
|
40
|
-
if (!entry) throw new Error(`net.send: socket ${id} not found`);
|
|
41
|
-
return new Promise((resolve, reject) => {
|
|
42
|
-
entry.socket.write(data, (err) => {
|
|
43
|
-
if (err) reject(err);
|
|
44
|
-
else resolve(true);
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
},
|
|
48
|
-
|
|
49
|
-
read: (args) => {
|
|
50
|
-
requireArgs('net.read', args, 1);
|
|
51
|
-
const id = toStr(args[0]);
|
|
52
|
-
const entry = _sockets.get(id);
|
|
53
|
-
if (!entry) throw new Error(`net.read: socket ${id} not found`);
|
|
54
|
-
const data = entry.data;
|
|
55
|
-
entry.data = '';
|
|
56
|
-
return data;
|
|
57
|
-
},
|
|
58
|
-
|
|
59
|
-
close: (args) => {
|
|
60
|
-
requireArgs('net.close', args, 1);
|
|
61
|
-
const id = toStr(args[0]);
|
|
62
|
-
const entry = _sockets.get(id);
|
|
63
|
-
if (entry) {
|
|
64
|
-
entry.socket.destroy();
|
|
65
|
-
_sockets.delete(id);
|
|
66
|
-
return true;
|
|
67
|
-
}
|
|
68
|
-
const server = _servers.get(id);
|
|
69
|
-
if (server) {
|
|
70
|
-
server.close();
|
|
71
|
-
_servers.delete(id);
|
|
72
|
-
return true;
|
|
73
|
-
}
|
|
74
|
-
return false;
|
|
75
|
-
},
|
|
76
|
-
|
|
77
|
-
createServer: (args, callback) => {
|
|
78
|
-
requireArgs('net.createServer', args, 1);
|
|
79
|
-
const port = toNum(args[0]);
|
|
80
|
-
const host = toStr(args[1], '0.0.0.0');
|
|
81
|
-
const serverId = `tcp_${_nextId++}`;
|
|
82
|
-
|
|
83
|
-
const server = createServer((socket) => {
|
|
84
|
-
const connId = `conn_${_nextId++}`;
|
|
85
|
-
_sockets.set(connId, { socket, data: '' });
|
|
86
|
-
socket.on('data', (chunk) => {
|
|
87
|
-
const entry = _sockets.get(connId);
|
|
88
|
-
if (entry) entry.data += chunk.toString();
|
|
89
|
-
if (callback) callback([connId, chunk.toString()]);
|
|
90
|
-
});
|
|
91
|
-
socket.on('end', () => { _sockets.delete(connId); });
|
|
92
|
-
socket.on('error', () => { _sockets.delete(connId); });
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
server.listen(port, host);
|
|
96
|
-
_servers.set(serverId, server);
|
|
97
|
-
return serverId;
|
|
98
|
-
},
|
|
99
|
-
|
|
100
|
-
isIP: (args) => {
|
|
101
|
-
requireArgs('net.isIP', args, 1);
|
|
102
|
-
return isIP(toStr(args[0]));
|
|
103
|
-
},
|
|
104
|
-
|
|
105
|
-
isIPv4: (args) => {
|
|
106
|
-
requireArgs('net.isIPv4', args, 1);
|
|
107
|
-
return isIPv4(toStr(args[0]));
|
|
108
|
-
},
|
|
109
|
-
|
|
110
|
-
isIPv6: (args) => {
|
|
111
|
-
requireArgs('net.isIPv6', args, 1);
|
|
112
|
-
return isIPv6(toStr(args[0]));
|
|
113
|
-
},
|
|
114
|
-
|
|
115
|
-
active: () => ({
|
|
116
|
-
servers: Array.from(_servers.keys()),
|
|
117
|
-
sockets: Array.from(_sockets.keys())
|
|
118
|
-
})
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
export const NetFunctionMetadata = {
|
|
122
|
-
connect: {
|
|
123
|
-
description: 'Connect to a TCP server',
|
|
124
|
-
parameters: [
|
|
125
|
-
{ name: 'host', dataType: 'string', description: 'Host to connect to', formInputType: 'text', required: true },
|
|
126
|
-
{ name: 'port', dataType: 'number', description: 'Port number', formInputType: 'number', required: true }
|
|
127
|
-
],
|
|
128
|
-
returnType: 'string', returnDescription: 'Socket handle ID', example: 'net.connect "localhost" 8080'
|
|
129
|
-
},
|
|
130
|
-
send: {
|
|
131
|
-
description: 'Send data through a socket',
|
|
132
|
-
parameters: [
|
|
133
|
-
{ name: 'socketId', dataType: 'string', description: 'Socket handle ID', formInputType: 'text', required: true },
|
|
134
|
-
{ name: 'data', dataType: 'string', description: 'Data to send', formInputType: 'text', required: true }
|
|
135
|
-
],
|
|
136
|
-
returnType: 'boolean', returnDescription: 'true on success', example: 'net.send $sock "hello"'
|
|
137
|
-
},
|
|
138
|
-
read: {
|
|
139
|
-
description: 'Read buffered data from a socket',
|
|
140
|
-
parameters: [{ name: 'socketId', dataType: 'string', description: 'Socket handle ID', formInputType: 'text', required: true }],
|
|
141
|
-
returnType: 'string', returnDescription: 'Buffered data', example: 'net.read $sock'
|
|
142
|
-
},
|
|
143
|
-
close: {
|
|
144
|
-
description: 'Close a socket or server',
|
|
145
|
-
parameters: [{ name: 'id', dataType: 'string', description: 'Socket or server handle ID', formInputType: 'text', required: true }],
|
|
146
|
-
returnType: 'boolean', returnDescription: 'true if closed', example: 'net.close $sock'
|
|
147
|
-
},
|
|
148
|
-
createServer: {
|
|
149
|
-
description: 'Create a TCP server',
|
|
150
|
-
parameters: [
|
|
151
|
-
{ name: 'port', dataType: 'number', description: 'Port to listen on', formInputType: 'number', required: true },
|
|
152
|
-
{ name: 'host', dataType: 'string', description: 'Host (default: 0.0.0.0)', formInputType: 'text', required: false, defaultValue: '0.0.0.0' }
|
|
153
|
-
],
|
|
154
|
-
returnType: 'string', returnDescription: 'Server handle ID', example: 'net.createServer 9090'
|
|
155
|
-
},
|
|
156
|
-
isIP: {
|
|
157
|
-
description: 'Check if string is a valid IP (returns 0, 4, or 6)',
|
|
158
|
-
parameters: [{ name: 'address', dataType: 'string', description: 'Address to check', formInputType: 'text', required: true }],
|
|
159
|
-
returnType: 'number', returnDescription: '0 (invalid), 4 (IPv4), or 6 (IPv6)', example: 'net.isIP "192.168.1.1"'
|
|
160
|
-
},
|
|
161
|
-
isIPv4: {
|
|
162
|
-
description: 'Check if string is a valid IPv4 address',
|
|
163
|
-
parameters: [{ name: 'address', dataType: 'string', description: 'Address', formInputType: 'text', required: true }],
|
|
164
|
-
returnType: 'boolean', returnDescription: 'true if IPv4', example: 'net.isIPv4 "192.168.1.1"'
|
|
165
|
-
},
|
|
166
|
-
isIPv6: {
|
|
167
|
-
description: 'Check if string is a valid IPv6 address',
|
|
168
|
-
parameters: [{ name: 'address', dataType: 'string', description: 'Address', formInputType: 'text', required: true }],
|
|
169
|
-
returnType: 'boolean', returnDescription: 'true if IPv6', example: 'net.isIPv6 "::1"'
|
|
170
|
-
},
|
|
171
|
-
active: {
|
|
172
|
-
description: 'List active servers and sockets',
|
|
173
|
-
parameters: [],
|
|
174
|
-
returnType: 'object', returnDescription: 'Object with servers and sockets arrays', example: 'net.active'
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
export const NetModuleMetadata = {
|
|
179
|
-
description: 'TCP networking: connect, send, read, createServer, and IP utilities',
|
|
180
|
-
methods: Object.keys(NetFunctions)
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
export default {
|
|
184
|
-
name: 'net',
|
|
185
|
-
functions: NetFunctions,
|
|
186
|
-
functionMetadata: NetFunctionMetadata,
|
|
187
|
-
moduleMetadata: NetModuleMetadata,
|
|
188
|
-
global: false
|
|
189
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* Native net module for RobinPath.
|
|
3
|
+
* TCP client/server and socket operations.
|
|
4
|
+
*/
|
|
5
|
+
import { createServer, createConnection, isIP, isIPv4, isIPv6 } from 'node:net';
|
|
6
|
+
import { toStr, toNum, requireArgs } from './_helpers.js';
|
|
7
|
+
|
|
8
|
+
const _servers = new Map();
|
|
9
|
+
const _sockets = new Map();
|
|
10
|
+
let _nextId = 1;
|
|
11
|
+
|
|
12
|
+
export const NetFunctions = {
|
|
13
|
+
|
|
14
|
+
connect: (args) => {
|
|
15
|
+
requireArgs('net.connect', args, 2);
|
|
16
|
+
const host = toStr(args[0]);
|
|
17
|
+
const port = toNum(args[1]);
|
|
18
|
+
const id = `sock_${_nextId++}`;
|
|
19
|
+
|
|
20
|
+
return new Promise((resolve, reject) => {
|
|
21
|
+
const socket = createConnection({ host, port }, () => {
|
|
22
|
+
_sockets.set(id, { socket, data: '' });
|
|
23
|
+
socket.on('data', (chunk) => {
|
|
24
|
+
const entry = _sockets.get(id);
|
|
25
|
+
if (entry) entry.data += chunk.toString();
|
|
26
|
+
});
|
|
27
|
+
socket.on('end', () => { _sockets.delete(id); });
|
|
28
|
+
socket.on('error', () => { _sockets.delete(id); });
|
|
29
|
+
resolve(id);
|
|
30
|
+
});
|
|
31
|
+
socket.on('error', (err) => reject(new Error(`net.connect: ${err.message}`)));
|
|
32
|
+
});
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
send: (args) => {
|
|
36
|
+
requireArgs('net.send', args, 2);
|
|
37
|
+
const id = toStr(args[0]);
|
|
38
|
+
const data = toStr(args[1]);
|
|
39
|
+
const entry = _sockets.get(id);
|
|
40
|
+
if (!entry) throw new Error(`net.send: socket ${id} not found`);
|
|
41
|
+
return new Promise((resolve, reject) => {
|
|
42
|
+
entry.socket.write(data, (err) => {
|
|
43
|
+
if (err) reject(err);
|
|
44
|
+
else resolve(true);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
read: (args) => {
|
|
50
|
+
requireArgs('net.read', args, 1);
|
|
51
|
+
const id = toStr(args[0]);
|
|
52
|
+
const entry = _sockets.get(id);
|
|
53
|
+
if (!entry) throw new Error(`net.read: socket ${id} not found`);
|
|
54
|
+
const data = entry.data;
|
|
55
|
+
entry.data = '';
|
|
56
|
+
return data;
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
close: (args) => {
|
|
60
|
+
requireArgs('net.close', args, 1);
|
|
61
|
+
const id = toStr(args[0]);
|
|
62
|
+
const entry = _sockets.get(id);
|
|
63
|
+
if (entry) {
|
|
64
|
+
entry.socket.destroy();
|
|
65
|
+
_sockets.delete(id);
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
const server = _servers.get(id);
|
|
69
|
+
if (server) {
|
|
70
|
+
server.close();
|
|
71
|
+
_servers.delete(id);
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
return false;
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
createServer: (args, callback) => {
|
|
78
|
+
requireArgs('net.createServer', args, 1);
|
|
79
|
+
const port = toNum(args[0]);
|
|
80
|
+
const host = toStr(args[1], '0.0.0.0');
|
|
81
|
+
const serverId = `tcp_${_nextId++}`;
|
|
82
|
+
|
|
83
|
+
const server = createServer((socket) => {
|
|
84
|
+
const connId = `conn_${_nextId++}`;
|
|
85
|
+
_sockets.set(connId, { socket, data: '' });
|
|
86
|
+
socket.on('data', (chunk) => {
|
|
87
|
+
const entry = _sockets.get(connId);
|
|
88
|
+
if (entry) entry.data += chunk.toString();
|
|
89
|
+
if (callback) callback([connId, chunk.toString()]);
|
|
90
|
+
});
|
|
91
|
+
socket.on('end', () => { _sockets.delete(connId); });
|
|
92
|
+
socket.on('error', () => { _sockets.delete(connId); });
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
server.listen(port, host);
|
|
96
|
+
_servers.set(serverId, server);
|
|
97
|
+
return serverId;
|
|
98
|
+
},
|
|
99
|
+
|
|
100
|
+
isIP: (args) => {
|
|
101
|
+
requireArgs('net.isIP', args, 1);
|
|
102
|
+
return isIP(toStr(args[0]));
|
|
103
|
+
},
|
|
104
|
+
|
|
105
|
+
isIPv4: (args) => {
|
|
106
|
+
requireArgs('net.isIPv4', args, 1);
|
|
107
|
+
return isIPv4(toStr(args[0]));
|
|
108
|
+
},
|
|
109
|
+
|
|
110
|
+
isIPv6: (args) => {
|
|
111
|
+
requireArgs('net.isIPv6', args, 1);
|
|
112
|
+
return isIPv6(toStr(args[0]));
|
|
113
|
+
},
|
|
114
|
+
|
|
115
|
+
active: () => ({
|
|
116
|
+
servers: Array.from(_servers.keys()),
|
|
117
|
+
sockets: Array.from(_sockets.keys())
|
|
118
|
+
})
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export const NetFunctionMetadata = {
|
|
122
|
+
connect: {
|
|
123
|
+
description: 'Connect to a TCP server',
|
|
124
|
+
parameters: [
|
|
125
|
+
{ name: 'host', dataType: 'string', description: 'Host to connect to', formInputType: 'text', required: true },
|
|
126
|
+
{ name: 'port', dataType: 'number', description: 'Port number', formInputType: 'number', required: true }
|
|
127
|
+
],
|
|
128
|
+
returnType: 'string', returnDescription: 'Socket handle ID', example: 'net.connect "localhost" 8080'
|
|
129
|
+
},
|
|
130
|
+
send: {
|
|
131
|
+
description: 'Send data through a socket',
|
|
132
|
+
parameters: [
|
|
133
|
+
{ name: 'socketId', dataType: 'string', description: 'Socket handle ID', formInputType: 'text', required: true },
|
|
134
|
+
{ name: 'data', dataType: 'string', description: 'Data to send', formInputType: 'text', required: true }
|
|
135
|
+
],
|
|
136
|
+
returnType: 'boolean', returnDescription: 'true on success', example: 'net.send $sock "hello"'
|
|
137
|
+
},
|
|
138
|
+
read: {
|
|
139
|
+
description: 'Read buffered data from a socket',
|
|
140
|
+
parameters: [{ name: 'socketId', dataType: 'string', description: 'Socket handle ID', formInputType: 'text', required: true }],
|
|
141
|
+
returnType: 'string', returnDescription: 'Buffered data', example: 'net.read $sock'
|
|
142
|
+
},
|
|
143
|
+
close: {
|
|
144
|
+
description: 'Close a socket or server',
|
|
145
|
+
parameters: [{ name: 'id', dataType: 'string', description: 'Socket or server handle ID', formInputType: 'text', required: true }],
|
|
146
|
+
returnType: 'boolean', returnDescription: 'true if closed', example: 'net.close $sock'
|
|
147
|
+
},
|
|
148
|
+
createServer: {
|
|
149
|
+
description: 'Create a TCP server',
|
|
150
|
+
parameters: [
|
|
151
|
+
{ name: 'port', dataType: 'number', description: 'Port to listen on', formInputType: 'number', required: true },
|
|
152
|
+
{ name: 'host', dataType: 'string', description: 'Host (default: 0.0.0.0)', formInputType: 'text', required: false, defaultValue: '0.0.0.0' }
|
|
153
|
+
],
|
|
154
|
+
returnType: 'string', returnDescription: 'Server handle ID', example: 'net.createServer 9090'
|
|
155
|
+
},
|
|
156
|
+
isIP: {
|
|
157
|
+
description: 'Check if string is a valid IP (returns 0, 4, or 6)',
|
|
158
|
+
parameters: [{ name: 'address', dataType: 'string', description: 'Address to check', formInputType: 'text', required: true }],
|
|
159
|
+
returnType: 'number', returnDescription: '0 (invalid), 4 (IPv4), or 6 (IPv6)', example: 'net.isIP "192.168.1.1"'
|
|
160
|
+
},
|
|
161
|
+
isIPv4: {
|
|
162
|
+
description: 'Check if string is a valid IPv4 address',
|
|
163
|
+
parameters: [{ name: 'address', dataType: 'string', description: 'Address', formInputType: 'text', required: true }],
|
|
164
|
+
returnType: 'boolean', returnDescription: 'true if IPv4', example: 'net.isIPv4 "192.168.1.1"'
|
|
165
|
+
},
|
|
166
|
+
isIPv6: {
|
|
167
|
+
description: 'Check if string is a valid IPv6 address',
|
|
168
|
+
parameters: [{ name: 'address', dataType: 'string', description: 'Address', formInputType: 'text', required: true }],
|
|
169
|
+
returnType: 'boolean', returnDescription: 'true if IPv6', example: 'net.isIPv6 "::1"'
|
|
170
|
+
},
|
|
171
|
+
active: {
|
|
172
|
+
description: 'List active servers and sockets',
|
|
173
|
+
parameters: [],
|
|
174
|
+
returnType: 'object', returnDescription: 'Object with servers and sockets arrays', example: 'net.active'
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
export const NetModuleMetadata = {
|
|
179
|
+
description: 'TCP networking: connect, send, read, createServer, and IP utilities',
|
|
180
|
+
methods: Object.keys(NetFunctions)
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
export default {
|
|
184
|
+
name: 'net',
|
|
185
|
+
functions: NetFunctions,
|
|
186
|
+
functionMetadata: NetFunctionMetadata,
|
|
187
|
+
moduleMetadata: NetModuleMetadata,
|
|
188
|
+
global: false
|
|
189
|
+
};
|