@robinpath/cli 1.73.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.
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Shared helpers for RobinPath native modules.
3
+ */
4
+ import { resolve } from 'node:path';
5
+
6
+ /** Coerce value to string with fallback */
7
+ export function toStr(val, fallback = '') {
8
+ return val == null ? fallback : String(val);
9
+ }
10
+
11
+ /** Coerce value to number with fallback */
12
+ export function toNum(val, fallback = 0) {
13
+ const n = Number(val);
14
+ return Number.isNaN(n) ? fallback : n;
15
+ }
16
+
17
+ /** Coerce value to boolean */
18
+ export function toBool(val) {
19
+ if (val === 'false' || val === '0' || val === '') return false;
20
+ return Boolean(val);
21
+ }
22
+
23
+ /** Require minimum number of arguments or throw */
24
+ export function requireArgs(funcName, args, min) {
25
+ if (!args || args.length < min) {
26
+ throw new Error(`${funcName} requires at least ${min} argument(s)`);
27
+ }
28
+ }
29
+
30
+ /** Resolve a file path (handles relative + absolute) */
31
+ export function toPath(val) {
32
+ return resolve(String(val ?? ''));
33
+ }
@@ -0,0 +1,270 @@
1
+ /**
2
+ * Native assert module for RobinPath.
3
+ * Testing assertions with clear error messages.
4
+ */
5
+ import { toStr, requireArgs } from './_helpers.js';
6
+
7
+ function fail(message) {
8
+ const err = new Error(message);
9
+ err.__formattedMessage = message;
10
+ throw err;
11
+ }
12
+
13
+ export const AssertFunctions = {
14
+
15
+ ok: (args) => {
16
+ requireArgs('assert.ok', args, 1);
17
+ const val = args[0];
18
+ const msg = args[1] ? toStr(args[1]) : `Expected truthy, got ${JSON.stringify(val)}`;
19
+ if (!val) fail(msg);
20
+ return true;
21
+ },
22
+
23
+ equal: (args) => {
24
+ requireArgs('assert.equal', args, 2);
25
+ const actual = args[0];
26
+ const expected = args[1];
27
+ const msg = args[2] ? toStr(args[2]) : `Expected ${JSON.stringify(expected)}, got ${JSON.stringify(actual)}`;
28
+ if (actual != expected) fail(msg);
29
+ return true;
30
+ },
31
+
32
+ strictEqual: (args) => {
33
+ requireArgs('assert.strictEqual', args, 2);
34
+ const actual = args[0];
35
+ const expected = args[1];
36
+ const msg = args[2] ? toStr(args[2]) : `Expected strict ${JSON.stringify(expected)}, got ${JSON.stringify(actual)}`;
37
+ if (actual !== expected) fail(msg);
38
+ return true;
39
+ },
40
+
41
+ notEqual: (args) => {
42
+ requireArgs('assert.notEqual', args, 2);
43
+ const actual = args[0];
44
+ const expected = args[1];
45
+ const msg = args[2] ? toStr(args[2]) : `Expected not equal to ${JSON.stringify(expected)}`;
46
+ if (actual == expected) fail(msg);
47
+ return true;
48
+ },
49
+
50
+ deepEqual: (args) => {
51
+ requireArgs('assert.deepEqual', args, 2);
52
+ const actual = args[0];
53
+ const expected = args[1];
54
+ const msg = args[2] ? toStr(args[2]) : `Deep equal assertion failed`;
55
+ try {
56
+ if (JSON.stringify(actual) !== JSON.stringify(expected)) fail(msg);
57
+ } catch {
58
+ fail(msg);
59
+ }
60
+ return true;
61
+ },
62
+
63
+ notDeepEqual: (args) => {
64
+ requireArgs('assert.notDeepEqual', args, 2);
65
+ const msg = args[2] ? toStr(args[2]) : `Expected objects to not be deeply equal`;
66
+ try {
67
+ if (JSON.stringify(args[0]) === JSON.stringify(args[1])) fail(msg);
68
+ } catch {
69
+ return true;
70
+ }
71
+ return true;
72
+ },
73
+
74
+ truthy: (args) => {
75
+ requireArgs('assert.truthy', args, 1);
76
+ const msg = args[1] ? toStr(args[1]) : `Expected truthy, got ${JSON.stringify(args[0])}`;
77
+ if (!args[0]) fail(msg);
78
+ return true;
79
+ },
80
+
81
+ falsy: (args) => {
82
+ requireArgs('assert.falsy', args, 1);
83
+ const msg = args[1] ? toStr(args[1]) : `Expected falsy, got ${JSON.stringify(args[0])}`;
84
+ if (args[0]) fail(msg);
85
+ return true;
86
+ },
87
+
88
+ isNull: (args) => {
89
+ requireArgs('assert.isNull', args, 1);
90
+ const msg = args[1] ? toStr(args[1]) : `Expected null, got ${JSON.stringify(args[0])}`;
91
+ if (args[0] !== null) fail(msg);
92
+ return true;
93
+ },
94
+
95
+ isNotNull: (args) => {
96
+ requireArgs('assert.isNotNull', args, 1);
97
+ const msg = args[1] ? toStr(args[1]) : `Expected non-null value`;
98
+ if (args[0] === null) fail(msg);
99
+ return true;
100
+ },
101
+
102
+ isType: (args) => {
103
+ requireArgs('assert.isType', args, 2);
104
+ const val = args[0];
105
+ const expectedType = toStr(args[1]);
106
+ const actualType = val === null ? 'null' : Array.isArray(val) ? 'array' : typeof val;
107
+ const msg = args[2] ? toStr(args[2]) : `Expected type ${expectedType}, got ${actualType}`;
108
+ if (actualType !== expectedType) fail(msg);
109
+ return true;
110
+ },
111
+
112
+ contains: (args) => {
113
+ requireArgs('assert.contains', args, 2);
114
+ const haystack = args[0];
115
+ const needle = args[1];
116
+ const msg = args[2] ? toStr(args[2]) : `Expected to contain ${JSON.stringify(needle)}`;
117
+ if (typeof haystack === 'string') {
118
+ if (!haystack.includes(toStr(needle))) fail(msg);
119
+ } else if (Array.isArray(haystack)) {
120
+ if (!haystack.includes(needle)) fail(msg);
121
+ } else {
122
+ fail(`assert.contains: first argument must be string or array`);
123
+ }
124
+ return true;
125
+ },
126
+
127
+ notContains: (args) => {
128
+ requireArgs('assert.notContains', args, 2);
129
+ const haystack = args[0];
130
+ const needle = args[1];
131
+ const msg = args[2] ? toStr(args[2]) : `Expected to not contain ${JSON.stringify(needle)}`;
132
+ if (typeof haystack === 'string') {
133
+ if (haystack.includes(toStr(needle))) fail(msg);
134
+ } else if (Array.isArray(haystack)) {
135
+ if (haystack.includes(needle)) fail(msg);
136
+ }
137
+ return true;
138
+ },
139
+
140
+ match: (args) => {
141
+ requireArgs('assert.match', args, 2);
142
+ const str = toStr(args[0]);
143
+ const pattern = toStr(args[1]);
144
+ const msg = args[2] ? toStr(args[2]) : `Expected "${str}" to match ${pattern}`;
145
+ if (!new RegExp(pattern).test(str)) fail(msg);
146
+ return true;
147
+ },
148
+
149
+ notMatch: (args) => {
150
+ requireArgs('assert.notMatch', args, 2);
151
+ const str = toStr(args[0]);
152
+ const pattern = toStr(args[1]);
153
+ const msg = args[2] ? toStr(args[2]) : `Expected "${str}" to not match ${pattern}`;
154
+ if (new RegExp(pattern).test(str)) fail(msg);
155
+ return true;
156
+ },
157
+
158
+ greaterThan: (args) => {
159
+ requireArgs('assert.greaterThan', args, 2);
160
+ const a = Number(args[0]);
161
+ const b = Number(args[1]);
162
+ const msg = args[2] ? toStr(args[2]) : `Expected ${a} > ${b}`;
163
+ if (!(a > b)) fail(msg);
164
+ return true;
165
+ },
166
+
167
+ lessThan: (args) => {
168
+ requireArgs('assert.lessThan', args, 2);
169
+ const a = Number(args[0]);
170
+ const b = Number(args[1]);
171
+ const msg = args[2] ? toStr(args[2]) : `Expected ${a} < ${b}`;
172
+ if (!(a < b)) fail(msg);
173
+ return true;
174
+ },
175
+
176
+ between: (args) => {
177
+ requireArgs('assert.between', args, 3);
178
+ const val = Number(args[0]);
179
+ const min = Number(args[1]);
180
+ const max = Number(args[2]);
181
+ const msg = args[3] ? toStr(args[3]) : `Expected ${val} between ${min} and ${max}`;
182
+ if (val < min || val > max) fail(msg);
183
+ return true;
184
+ },
185
+
186
+ lengthOf: (args) => {
187
+ requireArgs('assert.lengthOf', args, 2);
188
+ const val = args[0];
189
+ const expected = Number(args[1]);
190
+ const actual = (typeof val === 'string' || Array.isArray(val)) ? val.length : Object.keys(val).length;
191
+ const msg = args[2] ? toStr(args[2]) : `Expected length ${expected}, got ${actual}`;
192
+ if (actual !== expected) fail(msg);
193
+ return true;
194
+ },
195
+
196
+ hasProperty: (args) => {
197
+ requireArgs('assert.hasProperty', args, 2);
198
+ const obj = args[0];
199
+ const prop = toStr(args[1]);
200
+ const msg = args[2] ? toStr(args[2]) : `Expected object to have property "${prop}"`;
201
+ if (typeof obj !== 'object' || obj === null || !(prop in obj)) fail(msg);
202
+ return true;
203
+ },
204
+
205
+ throws: async (args, callback) => {
206
+ const msg = args[0] ? toStr(args[0]) : 'Expected an error to be thrown';
207
+ if (!callback) fail('assert.throws requires a callback block');
208
+ try {
209
+ await callback([]);
210
+ fail(msg);
211
+ } catch {
212
+ return true;
213
+ }
214
+ },
215
+
216
+ doesNotThrow: async (args, callback) => {
217
+ const msg = args[0] ? toStr(args[0]) : 'Expected no error to be thrown';
218
+ if (!callback) fail('assert.doesNotThrow requires a callback block');
219
+ try {
220
+ await callback([]);
221
+ return true;
222
+ } catch (err) {
223
+ fail(`${msg}: ${err.message}`);
224
+ }
225
+ },
226
+
227
+ fail: (args) => {
228
+ const msg = args[0] ? toStr(args[0]) : 'Assertion failed';
229
+ fail(msg);
230
+ }
231
+ };
232
+
233
+ export const AssertFunctionMetadata = {
234
+ ok: { description: 'Assert value is truthy', parameters: [{ name: 'value', dataType: 'any', description: 'Value to check', formInputType: 'json', required: true }, { name: 'message', dataType: 'string', description: 'Error message', formInputType: 'text', required: false }], returnType: 'boolean', returnDescription: 'true if passes', example: 'assert.ok $val' },
235
+ equal: { description: 'Assert loose equality (==)', parameters: [{ name: 'actual', dataType: 'any', description: 'Actual value', formInputType: 'json', required: true }, { name: 'expected', dataType: 'any', description: 'Expected value', formInputType: 'json', required: true }], returnType: 'boolean', returnDescription: 'true if equal', example: 'assert.equal $a $b' },
236
+ strictEqual: { description: 'Assert strict equality (===)', parameters: [{ name: 'actual', dataType: 'any', description: 'Actual', formInputType: 'json', required: true }, { name: 'expected', dataType: 'any', description: 'Expected', formInputType: 'json', required: true }], returnType: 'boolean', returnDescription: 'true if strict equal', example: 'assert.strictEqual $a $b' },
237
+ notEqual: { description: 'Assert not equal', parameters: [{ name: 'actual', dataType: 'any', description: 'Actual', formInputType: 'json', required: true }, { name: 'expected', dataType: 'any', description: 'Not expected', formInputType: 'json', required: true }], returnType: 'boolean', returnDescription: 'true if not equal', example: 'assert.notEqual $a $b' },
238
+ deepEqual: { description: 'Assert deep equality', parameters: [{ name: 'actual', dataType: 'any', description: 'Actual', formInputType: 'json', required: true }, { name: 'expected', dataType: 'any', description: 'Expected', formInputType: 'json', required: true }], returnType: 'boolean', returnDescription: 'true if deeply equal', example: 'assert.deepEqual $a $b' },
239
+ truthy: { description: 'Assert truthy', parameters: [{ name: 'value', dataType: 'any', description: 'Value', formInputType: 'json', required: true }], returnType: 'boolean', returnDescription: 'true', example: 'assert.truthy $val' },
240
+ falsy: { description: 'Assert falsy', parameters: [{ name: 'value', dataType: 'any', description: 'Value', formInputType: 'json', required: true }], returnType: 'boolean', returnDescription: 'true', example: 'assert.falsy $val' },
241
+ isNull: { description: 'Assert null', parameters: [{ name: 'value', dataType: 'any', description: 'Value', formInputType: 'json', required: true }], returnType: 'boolean', returnDescription: 'true if null', example: 'assert.isNull $val' },
242
+ isNotNull: { description: 'Assert not null', parameters: [{ name: 'value', dataType: 'any', description: 'Value', formInputType: 'json', required: true }], returnType: 'boolean', returnDescription: 'true if not null', example: 'assert.isNotNull $val' },
243
+ isType: { description: 'Assert value type', parameters: [{ name: 'value', dataType: 'any', description: 'Value', formInputType: 'json', required: true }, { name: 'type', dataType: 'string', description: 'Expected type', formInputType: 'text', required: true }], returnType: 'boolean', returnDescription: 'true if type matches', example: 'assert.isType $val "string"' },
244
+ contains: { description: 'Assert string/array contains value', parameters: [{ name: 'haystack', dataType: 'any', description: 'String or array', formInputType: 'json', required: true }, { name: 'needle', dataType: 'any', description: 'Value to find', formInputType: 'json', required: true }], returnType: 'boolean', returnDescription: 'true if contains', example: 'assert.contains "hello world" "world"' },
245
+ match: { description: 'Assert string matches regex', parameters: [{ name: 'string', dataType: 'string', description: 'String to test', formInputType: 'text', required: true }, { name: 'pattern', dataType: 'string', description: 'Regex pattern', formInputType: 'text', required: true }], returnType: 'boolean', returnDescription: 'true if matches', example: 'assert.match "hello" "^he"' },
246
+ greaterThan: { description: 'Assert a > b', parameters: [{ name: 'a', dataType: 'number', description: 'Value', formInputType: 'number', required: true }, { name: 'b', dataType: 'number', description: 'Comparison', formInputType: 'number', required: true }], returnType: 'boolean', returnDescription: 'true if a > b', example: 'assert.greaterThan 5 3' },
247
+ lessThan: { description: 'Assert a < b', parameters: [{ name: 'a', dataType: 'number', description: 'Value', formInputType: 'number', required: true }, { name: 'b', dataType: 'number', description: 'Comparison', formInputType: 'number', required: true }], returnType: 'boolean', returnDescription: 'true if a < b', example: 'assert.lessThan 3 5' },
248
+ between: { description: 'Assert value is between min and max', parameters: [{ name: 'value', dataType: 'number', description: 'Value', formInputType: 'number', required: true }, { name: 'min', dataType: 'number', description: 'Minimum', formInputType: 'number', required: true }, { name: 'max', dataType: 'number', description: 'Maximum', formInputType: 'number', required: true }], returnType: 'boolean', returnDescription: 'true if in range', example: 'assert.between 5 1 10' },
249
+ lengthOf: { description: 'Assert length of string/array/object', parameters: [{ name: 'value', dataType: 'any', description: 'Value', formInputType: 'json', required: true }, { name: 'length', dataType: 'number', description: 'Expected length', formInputType: 'number', required: true }], returnType: 'boolean', returnDescription: 'true if length matches', example: 'assert.lengthOf [1,2,3] 3' },
250
+ hasProperty: { description: 'Assert object has a property', parameters: [{ name: 'object', dataType: 'object', description: 'Object', formInputType: 'json', required: true }, { name: 'property', dataType: 'string', description: 'Property name', formInputType: 'text', required: true }], returnType: 'boolean', returnDescription: 'true if has property', example: 'assert.hasProperty $obj "name"' },
251
+ notDeepEqual: { description: 'Assert not deeply equal', parameters: [{ name: 'actual', dataType: 'any', description: 'Actual', formInputType: 'json', required: true }, { name: 'expected', dataType: 'any', description: 'Not expected', formInputType: 'json', required: true }], returnType: 'boolean', returnDescription: 'true if not deeply equal', example: 'assert.notDeepEqual $a $b' },
252
+ notContains: { description: 'Assert string/array does not contain value', parameters: [{ name: 'haystack', dataType: 'any', description: 'String or array', formInputType: 'json', required: true }, { name: 'needle', dataType: 'any', description: 'Value to check absence', formInputType: 'json', required: true }], returnType: 'boolean', returnDescription: 'true if not contains', example: 'assert.notContains "hello" "xyz"' },
253
+ notMatch: { description: 'Assert string does not match regex', parameters: [{ name: 'string', dataType: 'string', description: 'String to test', formInputType: 'text', required: true }, { name: 'pattern', dataType: 'string', description: 'Regex pattern', formInputType: 'text', required: true }], returnType: 'boolean', returnDescription: 'true if not matches', example: 'assert.notMatch "hello" "^xyz"' },
254
+ throws: { description: 'Assert callback throws an error', parameters: [{ name: 'message', dataType: 'string', description: 'Error message if no throw', formInputType: 'text', required: false }], returnType: 'boolean', returnDescription: 'true if threw', example: 'assert.throws "Should error"' },
255
+ doesNotThrow: { description: 'Assert callback does not throw', parameters: [{ name: 'message', dataType: 'string', description: 'Error message if throws', formInputType: 'text', required: false }], returnType: 'boolean', returnDescription: 'true if no throw', example: 'assert.doesNotThrow "Should not error"' },
256
+ fail: { description: 'Force assertion failure', parameters: [{ name: 'message', dataType: 'string', description: 'Failure message', formInputType: 'text', required: false }], returnType: 'null', returnDescription: 'Always throws', example: 'assert.fail "Not implemented"' }
257
+ };
258
+
259
+ export const AssertModuleMetadata = {
260
+ description: 'Assertions: equal, deepEqual, truthy, falsy, contains, match, greaterThan, throws, and more',
261
+ methods: Object.keys(AssertFunctions)
262
+ };
263
+
264
+ export default {
265
+ name: 'assert',
266
+ functions: AssertFunctions,
267
+ functionMetadata: AssertFunctionMetadata,
268
+ moduleMetadata: AssertModuleMetadata,
269
+ global: false
270
+ };
@@ -0,0 +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
+ };