fix(plugins): bind a Buffer a plugin passes to its own database as bytes

A Buffer crosses the plugin IPC as its JSON form, so db.query, db.exec and db.tx now turn that form back into the bytes before binding, as the plugin docs promise.
This commit is contained in:
Maurice
2026-11-23 15:36:29 +01:00
parent 10f0cb7d04
commit ac5c91bcaf
3 changed files with 52 additions and 2 deletions
+13 -1
View File
@@ -1,5 +1,5 @@
import { BadParams } from '../../../src/nest-rpc/rpc-errors';
import { optionalRowIdParam, rowIdParam } from '../../../src/nest-rpc/rpc-params';
import { asArgs, asTxOps, optionalRowIdParam, rowIdParam } from '../../../src/nest-rpc/rpc-params';
import { describe, expect, it } from 'vitest';
@@ -24,3 +24,15 @@ describe('rowIdParam', () => {
}
});
});
describe('asArgs', () => {
it('RPCPARAM-004: a Buffer that crossed the JSON IPC is bound as its bytes again, in query args and tx ops', () => {
const wire = JSON.parse(JSON.stringify([Buffer.from([1, 0, 255]), 'k', { type: 'Buffer', data: [1, 300] }]));
const [bytes, key, odd] = asArgs(wire);
expect(Buffer.isBuffer(bytes) && [...bytes]).toEqual([1, 0, 255]);
expect(key).toBe('k');
expect(odd).toEqual({ type: 'Buffer', data: [1, 300] });
const [op] = asTxOps([{ sql: 'SELECT ?', args: wire }]);
expect(Buffer.isBuffer(op?.args?.[0])).toBe(true);
});
});