@robinpath/cli 1.75.0 → 1.77.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/modules/buffer.js CHANGED
@@ -1,245 +1,245 @@
1
- /**
2
- * Native buffer module for RobinPath.
3
- * Buffer operations for binary data handling.
4
- */
5
- import { toStr, toNum, requireArgs } from './_helpers.js';
6
-
7
- export const BufferFunctions = {
8
-
9
- alloc: (args) => {
10
- const size = toNum(args[0], 0);
11
- const fill = args[1] != null ? toNum(args[1], 0) : 0;
12
- return Buffer.alloc(size, fill).toString('base64');
13
- },
14
-
15
- from: (args) => {
16
- requireArgs('buffer.from', args, 1);
17
- const data = args[0];
18
- const encoding = toStr(args[1], 'utf-8');
19
- if (typeof data === 'string') {
20
- return Buffer.from(data, encoding).toString('base64');
21
- }
22
- if (Array.isArray(data)) {
23
- return Buffer.from(data).toString('base64');
24
- }
25
- return Buffer.from(String(data)).toString('base64');
26
- },
27
-
28
- toString: (args) => {
29
- requireArgs('buffer.toString', args, 1);
30
- const base64 = toStr(args[0]);
31
- const encoding = toStr(args[1], 'utf-8');
32
- return Buffer.from(base64, 'base64').toString(encoding);
33
- },
34
-
35
- toJSON: (args) => {
36
- requireArgs('buffer.toJSON', args, 1);
37
- const buf = Buffer.from(toStr(args[0]), 'base64');
38
- return { type: 'Buffer', data: Array.from(buf) };
39
- },
40
-
41
- concat: (args) => {
42
- if (!Array.isArray(args[0])) throw new Error('buffer.concat requires an array of base64 buffers');
43
- const buffers = args[0].map(b => Buffer.from(toStr(b), 'base64'));
44
- return Buffer.concat(buffers).toString('base64');
45
- },
46
-
47
- compare: (args) => {
48
- requireArgs('buffer.compare', args, 2);
49
- const a = Buffer.from(toStr(args[0]), 'base64');
50
- const b = Buffer.from(toStr(args[1]), 'base64');
51
- return Buffer.compare(a, b);
52
- },
53
-
54
- equals: (args) => {
55
- requireArgs('buffer.equals', args, 2);
56
- const a = Buffer.from(toStr(args[0]), 'base64');
57
- const b = Buffer.from(toStr(args[1]), 'base64');
58
- return a.equals(b);
59
- },
60
-
61
- slice: (args) => {
62
- requireArgs('buffer.slice', args, 1);
63
- const buf = Buffer.from(toStr(args[0]), 'base64');
64
- const start = toNum(args[1], 0);
65
- const end = args[2] != null ? toNum(args[2]) : buf.length;
66
- return buf.subarray(start, end).toString('base64');
67
- },
68
-
69
- length: (args) => {
70
- requireArgs('buffer.length', args, 1);
71
- return Buffer.from(toStr(args[0]), 'base64').length;
72
- },
73
-
74
- byteLength: (args) => {
75
- requireArgs('buffer.byteLength', args, 1);
76
- const data = toStr(args[0]);
77
- const encoding = toStr(args[1], 'utf-8');
78
- return Buffer.byteLength(data, encoding);
79
- },
80
-
81
- isBuffer: (args) => {
82
- requireArgs('buffer.isBuffer', args, 1);
83
- // In RobinPath, buffers are base64 strings — check if valid base64
84
- try {
85
- const str = toStr(args[0]);
86
- const buf = Buffer.from(str, 'base64');
87
- return buf.toString('base64') === str;
88
- } catch { return false; }
89
- },
90
-
91
- fill: (args) => {
92
- requireArgs('buffer.fill', args, 2);
93
- const buf = Buffer.from(toStr(args[0]), 'base64');
94
- const value = toNum(args[1], 0);
95
- buf.fill(value);
96
- return buf.toString('base64');
97
- },
98
-
99
- indexOf: (args) => {
100
- requireArgs('buffer.indexOf', args, 2);
101
- const buf = Buffer.from(toStr(args[0]), 'base64');
102
- const search = toStr(args[1]);
103
- return buf.indexOf(search);
104
- },
105
-
106
- copy: (args) => {
107
- requireArgs('buffer.copy', args, 1);
108
- const buf = Buffer.from(toStr(args[0]), 'base64');
109
- return Buffer.from(buf).toString('base64');
110
- },
111
-
112
- toHex: (args) => {
113
- requireArgs('buffer.toHex', args, 1);
114
- return Buffer.from(toStr(args[0]), 'base64').toString('hex');
115
- },
116
-
117
- fromHex: (args) => {
118
- requireArgs('buffer.fromHex', args, 1);
119
- return Buffer.from(toStr(args[0]), 'hex').toString('base64');
120
- }
121
- };
122
-
123
- export const BufferFunctionMetadata = {
124
- alloc: {
125
- description: 'Allocate a buffer of given size',
126
- parameters: [
127
- { name: 'size', dataType: 'number', description: 'Size in bytes', formInputType: 'number', required: true },
128
- { name: 'fill', dataType: 'number', description: 'Fill value (default: 0)', formInputType: 'number', required: false, defaultValue: 0 }
129
- ],
130
- returnType: 'string', returnDescription: 'Base64-encoded buffer', example: 'buffer.alloc 16'
131
- },
132
- from: {
133
- description: 'Create a buffer from string or array',
134
- parameters: [
135
- { name: 'data', dataType: 'any', description: 'Input data', formInputType: 'text', required: true },
136
- { name: 'encoding', dataType: 'string', description: 'Input encoding (default: utf-8)', formInputType: 'text', required: false, defaultValue: 'utf-8' }
137
- ],
138
- returnType: 'string', returnDescription: 'Base64-encoded buffer', example: 'buffer.from "hello"'
139
- },
140
- toString: {
141
- description: 'Convert buffer to string',
142
- parameters: [
143
- { name: 'buffer', dataType: 'string', description: 'Base64-encoded buffer', formInputType: 'text', required: true },
144
- { name: 'encoding', dataType: 'string', description: 'Output encoding (default: utf-8)', formInputType: 'text', required: false, defaultValue: 'utf-8' }
145
- ],
146
- returnType: 'string', returnDescription: 'Decoded string', example: 'buffer.toString $buf'
147
- },
148
- toJSON: {
149
- description: 'Convert buffer to JSON representation',
150
- parameters: [{ name: 'buffer', dataType: 'string', description: 'Base64-encoded buffer', formInputType: 'text', required: true }],
151
- returnType: 'object', returnDescription: '{type, data} object', example: 'buffer.toJSON $buf'
152
- },
153
- concat: {
154
- description: 'Concatenate multiple buffers',
155
- parameters: [{ name: 'buffers', dataType: 'array', description: 'Array of base64-encoded buffers', formInputType: 'json', required: true }],
156
- returnType: 'string', returnDescription: 'Concatenated base64-encoded buffer', example: 'buffer.concat [$buf1, $buf2]'
157
- },
158
- compare: {
159
- description: 'Compare two buffers (-1, 0, 1)',
160
- parameters: [
161
- { name: 'a', dataType: 'string', description: 'First buffer', formInputType: 'text', required: true },
162
- { name: 'b', dataType: 'string', description: 'Second buffer', formInputType: 'text', required: true }
163
- ],
164
- returnType: 'number', returnDescription: '-1, 0, or 1', example: 'buffer.compare $buf1 $buf2'
165
- },
166
- equals: {
167
- description: 'Check if two buffers are equal',
168
- parameters: [
169
- { name: 'a', dataType: 'string', description: 'First buffer', formInputType: 'text', required: true },
170
- { name: 'b', dataType: 'string', description: 'Second buffer', formInputType: 'text', required: true }
171
- ],
172
- returnType: 'boolean', returnDescription: 'true if equal', example: 'buffer.equals $buf1 $buf2'
173
- },
174
- slice: {
175
- description: 'Get a slice of a buffer',
176
- parameters: [
177
- { name: 'buffer', dataType: 'string', description: 'Base64-encoded buffer', formInputType: 'text', required: true },
178
- { name: 'start', dataType: 'number', description: 'Start index (default: 0)', formInputType: 'number', required: false, defaultValue: 0 },
179
- { name: 'end', dataType: 'number', description: 'End index (default: length)', formInputType: 'number', required: false }
180
- ],
181
- returnType: 'string', returnDescription: 'Base64-encoded slice', example: 'buffer.slice $buf 0 10'
182
- },
183
- length: {
184
- description: 'Get buffer length in bytes',
185
- parameters: [{ name: 'buffer', dataType: 'string', description: 'Base64-encoded buffer', formInputType: 'text', required: true }],
186
- returnType: 'number', returnDescription: 'Length in bytes', example: 'buffer.length $buf'
187
- },
188
- byteLength: {
189
- description: 'Get byte length of a string',
190
- parameters: [
191
- { name: 'string', dataType: 'string', description: 'Input string', formInputType: 'text', required: true },
192
- { name: 'encoding', dataType: 'string', description: 'Encoding (default: utf-8)', formInputType: 'text', required: false, defaultValue: 'utf-8' }
193
- ],
194
- returnType: 'number', returnDescription: 'Byte length', example: 'buffer.byteLength "hello"'
195
- },
196
- isBuffer: {
197
- description: 'Check if value is a valid base64 buffer',
198
- parameters: [{ name: 'value', dataType: 'any', description: 'Value to check', formInputType: 'text', required: true }],
199
- returnType: 'boolean', returnDescription: 'true if valid buffer', example: 'buffer.isBuffer $val'
200
- },
201
- fill: {
202
- description: 'Fill buffer with a value',
203
- parameters: [
204
- { name: 'buffer', dataType: 'string', description: 'Base64-encoded buffer', formInputType: 'text', required: true },
205
- { name: 'value', dataType: 'number', description: 'Fill value', formInputType: 'number', required: true }
206
- ],
207
- returnType: 'string', returnDescription: 'Filled base64-encoded buffer', example: 'buffer.fill $buf 0'
208
- },
209
- indexOf: {
210
- description: 'Find position of a value in buffer',
211
- parameters: [
212
- { name: 'buffer', dataType: 'string', description: 'Base64-encoded buffer', formInputType: 'text', required: true },
213
- { name: 'search', dataType: 'string', description: 'Value to find', formInputType: 'text', required: true }
214
- ],
215
- returnType: 'number', returnDescription: 'Index or -1', example: 'buffer.indexOf $buf "hello"'
216
- },
217
- copy: {
218
- description: 'Copy a buffer',
219
- parameters: [{ name: 'buffer', dataType: 'string', description: 'Base64-encoded buffer', formInputType: 'text', required: true }],
220
- returnType: 'string', returnDescription: 'Copied base64-encoded buffer', example: 'buffer.copy $buf'
221
- },
222
- toHex: {
223
- description: 'Convert buffer to hex string',
224
- parameters: [{ name: 'buffer', dataType: 'string', description: 'Base64-encoded buffer', formInputType: 'text', required: true }],
225
- returnType: 'string', returnDescription: 'Hex string', example: 'buffer.toHex $buf'
226
- },
227
- fromHex: {
228
- description: 'Create buffer from hex string',
229
- parameters: [{ name: 'hex', dataType: 'string', description: 'Hex string', formInputType: 'text', required: true }],
230
- returnType: 'string', returnDescription: 'Base64-encoded buffer', example: 'buffer.fromHex "68656c6c6f"'
231
- }
232
- };
233
-
234
- export const BufferModuleMetadata = {
235
- description: 'Buffer operations for binary data: alloc, from, concat, compare, slice, encode/decode',
236
- methods: Object.keys(BufferFunctions)
237
- };
238
-
239
- export default {
240
- name: 'buffer',
241
- functions: BufferFunctions,
242
- functionMetadata: BufferFunctionMetadata,
243
- moduleMetadata: BufferModuleMetadata,
244
- global: false
245
- };
1
+ /**
2
+ * Native buffer module for RobinPath.
3
+ * Buffer operations for binary data handling.
4
+ */
5
+ import { toStr, toNum, requireArgs } from './_helpers.js';
6
+
7
+ export const BufferFunctions = {
8
+
9
+ alloc: (args) => {
10
+ const size = toNum(args[0], 0);
11
+ const fill = args[1] != null ? toNum(args[1], 0) : 0;
12
+ return Buffer.alloc(size, fill).toString('base64');
13
+ },
14
+
15
+ from: (args) => {
16
+ requireArgs('buffer.from', args, 1);
17
+ const data = args[0];
18
+ const encoding = toStr(args[1], 'utf-8');
19
+ if (typeof data === 'string') {
20
+ return Buffer.from(data, encoding).toString('base64');
21
+ }
22
+ if (Array.isArray(data)) {
23
+ return Buffer.from(data).toString('base64');
24
+ }
25
+ return Buffer.from(String(data)).toString('base64');
26
+ },
27
+
28
+ toString: (args) => {
29
+ requireArgs('buffer.toString', args, 1);
30
+ const base64 = toStr(args[0]);
31
+ const encoding = toStr(args[1], 'utf-8');
32
+ return Buffer.from(base64, 'base64').toString(encoding);
33
+ },
34
+
35
+ toJSON: (args) => {
36
+ requireArgs('buffer.toJSON', args, 1);
37
+ const buf = Buffer.from(toStr(args[0]), 'base64');
38
+ return { type: 'Buffer', data: Array.from(buf) };
39
+ },
40
+
41
+ concat: (args) => {
42
+ if (!Array.isArray(args[0])) throw new Error('buffer.concat requires an array of base64 buffers');
43
+ const buffers = args[0].map(b => Buffer.from(toStr(b), 'base64'));
44
+ return Buffer.concat(buffers).toString('base64');
45
+ },
46
+
47
+ compare: (args) => {
48
+ requireArgs('buffer.compare', args, 2);
49
+ const a = Buffer.from(toStr(args[0]), 'base64');
50
+ const b = Buffer.from(toStr(args[1]), 'base64');
51
+ return Buffer.compare(a, b);
52
+ },
53
+
54
+ equals: (args) => {
55
+ requireArgs('buffer.equals', args, 2);
56
+ const a = Buffer.from(toStr(args[0]), 'base64');
57
+ const b = Buffer.from(toStr(args[1]), 'base64');
58
+ return a.equals(b);
59
+ },
60
+
61
+ slice: (args) => {
62
+ requireArgs('buffer.slice', args, 1);
63
+ const buf = Buffer.from(toStr(args[0]), 'base64');
64
+ const start = toNum(args[1], 0);
65
+ const end = args[2] != null ? toNum(args[2]) : buf.length;
66
+ return buf.subarray(start, end).toString('base64');
67
+ },
68
+
69
+ length: (args) => {
70
+ requireArgs('buffer.length', args, 1);
71
+ return Buffer.from(toStr(args[0]), 'base64').length;
72
+ },
73
+
74
+ byteLength: (args) => {
75
+ requireArgs('buffer.byteLength', args, 1);
76
+ const data = toStr(args[0]);
77
+ const encoding = toStr(args[1], 'utf-8');
78
+ return Buffer.byteLength(data, encoding);
79
+ },
80
+
81
+ isBuffer: (args) => {
82
+ requireArgs('buffer.isBuffer', args, 1);
83
+ // In RobinPath, buffers are base64 strings — check if valid base64
84
+ try {
85
+ const str = toStr(args[0]);
86
+ const buf = Buffer.from(str, 'base64');
87
+ return buf.toString('base64') === str;
88
+ } catch { return false; }
89
+ },
90
+
91
+ fill: (args) => {
92
+ requireArgs('buffer.fill', args, 2);
93
+ const buf = Buffer.from(toStr(args[0]), 'base64');
94
+ const value = toNum(args[1], 0);
95
+ buf.fill(value);
96
+ return buf.toString('base64');
97
+ },
98
+
99
+ indexOf: (args) => {
100
+ requireArgs('buffer.indexOf', args, 2);
101
+ const buf = Buffer.from(toStr(args[0]), 'base64');
102
+ const search = toStr(args[1]);
103
+ return buf.indexOf(search);
104
+ },
105
+
106
+ copy: (args) => {
107
+ requireArgs('buffer.copy', args, 1);
108
+ const buf = Buffer.from(toStr(args[0]), 'base64');
109
+ return Buffer.from(buf).toString('base64');
110
+ },
111
+
112
+ toHex: (args) => {
113
+ requireArgs('buffer.toHex', args, 1);
114
+ return Buffer.from(toStr(args[0]), 'base64').toString('hex');
115
+ },
116
+
117
+ fromHex: (args) => {
118
+ requireArgs('buffer.fromHex', args, 1);
119
+ return Buffer.from(toStr(args[0]), 'hex').toString('base64');
120
+ }
121
+ };
122
+
123
+ export const BufferFunctionMetadata = {
124
+ alloc: {
125
+ description: 'Allocate a buffer of given size',
126
+ parameters: [
127
+ { name: 'size', dataType: 'number', description: 'Size in bytes', formInputType: 'number', required: true },
128
+ { name: 'fill', dataType: 'number', description: 'Fill value (default: 0)', formInputType: 'number', required: false, defaultValue: 0 }
129
+ ],
130
+ returnType: 'string', returnDescription: 'Base64-encoded buffer', example: 'buffer.alloc 16'
131
+ },
132
+ from: {
133
+ description: 'Create a buffer from string or array',
134
+ parameters: [
135
+ { name: 'data', dataType: 'any', description: 'Input data', formInputType: 'text', required: true },
136
+ { name: 'encoding', dataType: 'string', description: 'Input encoding (default: utf-8)', formInputType: 'text', required: false, defaultValue: 'utf-8' }
137
+ ],
138
+ returnType: 'string', returnDescription: 'Base64-encoded buffer', example: 'buffer.from "hello"'
139
+ },
140
+ toString: {
141
+ description: 'Convert buffer to string',
142
+ parameters: [
143
+ { name: 'buffer', dataType: 'string', description: 'Base64-encoded buffer', formInputType: 'text', required: true },
144
+ { name: 'encoding', dataType: 'string', description: 'Output encoding (default: utf-8)', formInputType: 'text', required: false, defaultValue: 'utf-8' }
145
+ ],
146
+ returnType: 'string', returnDescription: 'Decoded string', example: 'buffer.toString $buf'
147
+ },
148
+ toJSON: {
149
+ description: 'Convert buffer to JSON representation',
150
+ parameters: [{ name: 'buffer', dataType: 'string', description: 'Base64-encoded buffer', formInputType: 'text', required: true }],
151
+ returnType: 'object', returnDescription: '{type, data} object', example: 'buffer.toJSON $buf'
152
+ },
153
+ concat: {
154
+ description: 'Concatenate multiple buffers',
155
+ parameters: [{ name: 'buffers', dataType: 'array', description: 'Array of base64-encoded buffers', formInputType: 'json', required: true }],
156
+ returnType: 'string', returnDescription: 'Concatenated base64-encoded buffer', example: 'buffer.concat [$buf1, $buf2]'
157
+ },
158
+ compare: {
159
+ description: 'Compare two buffers (-1, 0, 1)',
160
+ parameters: [
161
+ { name: 'a', dataType: 'string', description: 'First buffer', formInputType: 'text', required: true },
162
+ { name: 'b', dataType: 'string', description: 'Second buffer', formInputType: 'text', required: true }
163
+ ],
164
+ returnType: 'number', returnDescription: '-1, 0, or 1', example: 'buffer.compare $buf1 $buf2'
165
+ },
166
+ equals: {
167
+ description: 'Check if two buffers are equal',
168
+ parameters: [
169
+ { name: 'a', dataType: 'string', description: 'First buffer', formInputType: 'text', required: true },
170
+ { name: 'b', dataType: 'string', description: 'Second buffer', formInputType: 'text', required: true }
171
+ ],
172
+ returnType: 'boolean', returnDescription: 'true if equal', example: 'buffer.equals $buf1 $buf2'
173
+ },
174
+ slice: {
175
+ description: 'Get a slice of a buffer',
176
+ parameters: [
177
+ { name: 'buffer', dataType: 'string', description: 'Base64-encoded buffer', formInputType: 'text', required: true },
178
+ { name: 'start', dataType: 'number', description: 'Start index (default: 0)', formInputType: 'number', required: false, defaultValue: 0 },
179
+ { name: 'end', dataType: 'number', description: 'End index (default: length)', formInputType: 'number', required: false }
180
+ ],
181
+ returnType: 'string', returnDescription: 'Base64-encoded slice', example: 'buffer.slice $buf 0 10'
182
+ },
183
+ length: {
184
+ description: 'Get buffer length in bytes',
185
+ parameters: [{ name: 'buffer', dataType: 'string', description: 'Base64-encoded buffer', formInputType: 'text', required: true }],
186
+ returnType: 'number', returnDescription: 'Length in bytes', example: 'buffer.length $buf'
187
+ },
188
+ byteLength: {
189
+ description: 'Get byte length of a string',
190
+ parameters: [
191
+ { name: 'string', dataType: 'string', description: 'Input string', formInputType: 'text', required: true },
192
+ { name: 'encoding', dataType: 'string', description: 'Encoding (default: utf-8)', formInputType: 'text', required: false, defaultValue: 'utf-8' }
193
+ ],
194
+ returnType: 'number', returnDescription: 'Byte length', example: 'buffer.byteLength "hello"'
195
+ },
196
+ isBuffer: {
197
+ description: 'Check if value is a valid base64 buffer',
198
+ parameters: [{ name: 'value', dataType: 'any', description: 'Value to check', formInputType: 'text', required: true }],
199
+ returnType: 'boolean', returnDescription: 'true if valid buffer', example: 'buffer.isBuffer $val'
200
+ },
201
+ fill: {
202
+ description: 'Fill buffer with a value',
203
+ parameters: [
204
+ { name: 'buffer', dataType: 'string', description: 'Base64-encoded buffer', formInputType: 'text', required: true },
205
+ { name: 'value', dataType: 'number', description: 'Fill value', formInputType: 'number', required: true }
206
+ ],
207
+ returnType: 'string', returnDescription: 'Filled base64-encoded buffer', example: 'buffer.fill $buf 0'
208
+ },
209
+ indexOf: {
210
+ description: 'Find position of a value in buffer',
211
+ parameters: [
212
+ { name: 'buffer', dataType: 'string', description: 'Base64-encoded buffer', formInputType: 'text', required: true },
213
+ { name: 'search', dataType: 'string', description: 'Value to find', formInputType: 'text', required: true }
214
+ ],
215
+ returnType: 'number', returnDescription: 'Index or -1', example: 'buffer.indexOf $buf "hello"'
216
+ },
217
+ copy: {
218
+ description: 'Copy a buffer',
219
+ parameters: [{ name: 'buffer', dataType: 'string', description: 'Base64-encoded buffer', formInputType: 'text', required: true }],
220
+ returnType: 'string', returnDescription: 'Copied base64-encoded buffer', example: 'buffer.copy $buf'
221
+ },
222
+ toHex: {
223
+ description: 'Convert buffer to hex string',
224
+ parameters: [{ name: 'buffer', dataType: 'string', description: 'Base64-encoded buffer', formInputType: 'text', required: true }],
225
+ returnType: 'string', returnDescription: 'Hex string', example: 'buffer.toHex $buf'
226
+ },
227
+ fromHex: {
228
+ description: 'Create buffer from hex string',
229
+ parameters: [{ name: 'hex', dataType: 'string', description: 'Hex string', formInputType: 'text', required: true }],
230
+ returnType: 'string', returnDescription: 'Base64-encoded buffer', example: 'buffer.fromHex "68656c6c6f"'
231
+ }
232
+ };
233
+
234
+ export const BufferModuleMetadata = {
235
+ description: 'Buffer operations for binary data: alloc, from, concat, compare, slice, encode/decode',
236
+ methods: Object.keys(BufferFunctions)
237
+ };
238
+
239
+ export default {
240
+ name: 'buffer',
241
+ functions: BufferFunctions,
242
+ functionMetadata: BufferFunctionMetadata,
243
+ moduleMetadata: BufferModuleMetadata,
244
+ global: false
245
+ };