mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-28 23:50:08 +00:00
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:
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user