resplite 1.5.2 → 1.5.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "resplite",
3
- "version": "1.5.2",
3
+ "version": "1.5.4",
4
4
  "description": "A RESP2 server with practical Redis compatibility, backed by SQLite",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -289,14 +289,21 @@ export function dispatch(engine, argv, context) {
289
289
  return { error: 'ERR wrong number of arguments' };
290
290
  }
291
291
  const cmd = (Buffer.isBuffer(argv[0]) ? argv[0].toString('utf8') : String(argv[0])).toUpperCase();
292
+ const args = argv.slice(1);
293
+ const argvStrings = argv.map((b) => (Buffer.isBuffer(b) ? b.toString('utf8') : String(b)));
292
294
  const policy = compileCommandPolicy(context?.commandPolicy);
293
295
  const commandResolution = resolveIncomingCommand(cmd, policy);
294
296
  if (commandResolution.blocked) {
297
+ context?.onUnknownCommand?.({
298
+ command: cmd,
299
+ argsCount: args.length,
300
+ argv: argvStrings ?? [cmd],
301
+ clientAddress: context?.clientAddress ?? '',
302
+ connectionId: context?.connectionId ?? 0,
303
+ });
295
304
  return { error: unsupported() };
296
305
  }
297
306
  const resolvedCommand = commandResolution.resolvedCommand;
298
- const args = argv.slice(1);
299
- const argvStrings = argv.map((b) => (Buffer.isBuffer(b) ? b.toString('utf8') : String(b)));
300
307
  if (context) {
301
308
  context.getCommandNames = () => listVisibleCommandNames(policy);
302
309
  context.resolveCommandForIntrospection = (name) => {
@@ -142,6 +142,33 @@ describe('createRESPlite', () => {
142
142
  assert.ok(sub.clientAddress.length > 0);
143
143
  });
144
144
 
145
+ it('onUnknownCommand hook is also called for disabled commands', async () => {
146
+ const unknownCalls = [];
147
+ const srv = await createRESPlite({
148
+ commandPolicy: {
149
+ disabled: ['MONITOR'],
150
+ },
151
+ hooks: {
152
+ onUnknownCommand(payload) {
153
+ unknownCalls.push(payload);
154
+ },
155
+ },
156
+ });
157
+ const client = await redisClient(srv.port);
158
+ try {
159
+ await client.sendCommand(['MONITOR']);
160
+ assert.fail('expected error');
161
+ } catch (e) {
162
+ assert.ok(e.message.includes('not supported'), e.message);
163
+ }
164
+ await client.quit();
165
+ await srv.close();
166
+
167
+ assert.equal(unknownCalls.length, 1);
168
+ assert.equal(unknownCalls[0].command, 'MONITOR');
169
+ assert.equal(unknownCalls[0].argsCount, 0);
170
+ });
171
+
145
172
  it('onCommandError hook is called when command returns or throws error', async () => {
146
173
  const errorCalls = [];
147
174
  const srv = await createRESPlite({