resplite 1.2.14 → 1.2.16

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/README.md CHANGED
@@ -63,14 +63,14 @@ const srv = await createRESPlite({
63
63
  port: 6380,
64
64
  db: './data.db',
65
65
  hooks: {
66
- onUnknownCommand({ command, argsCount, clientAddress }) {
67
- log.warn({ command, argsCount, clientAddress }, 'unsupported command');
66
+ onUnknownCommand({ command, argv, clientAddress }) {
67
+ log.warn({ command, argv, clientAddress }, 'unsupported command');
68
68
  },
69
- onCommandError({ command, error, clientAddress }) {
70
- log.warn({ command, error, clientAddress }, 'command error');
69
+ onCommandError({ command, argv, error, clientAddress }) {
70
+ log.warn({ command, argv, error, clientAddress }, 'command error');
71
71
  },
72
72
  onSocketError({ error, clientAddress }) {
73
- log.error({ err: error, clientAddress }, 'connection error');
73
+ log.error({ error, clientAddress }, 'connection error');
74
74
  },
75
75
  },
76
76
  });
@@ -78,8 +78,8 @@ const srv = await createRESPlite({
78
78
 
79
79
  Available hooks:
80
80
 
81
- - `onUnknownCommand`: client sent a command not implemented by RESPLite, such as `SUBSCRIBE` or `PUBLISH`.
82
- - `onCommandError`: a command failed because of wrong type, invalid args, or a handler error.
81
+ - `onUnknownCommand`: client sent a command not implemented by RESPLite, such as `SUBSCRIBE` or `PUBLISH`. Payload includes `argv` (full command line as strings, e.g. `['CLIENT','LIST']`) so you can log exactly what was sent.
82
+ - `onCommandError`: a command failed because of wrong type, invalid args, or a handler error. Payload includes `argv` for the full command line.
83
83
  - `onSocketError`: the connection socket emitted an error, for example `ECONNRESET`.
84
84
 
85
85
  If you want a tiny in-process smoke test that starts RESPLite and connects with the `redis` client in the same script, see [Minimal embedded example](#minimal-embedded-example) below.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "resplite",
3
- "version": "1.2.14",
3
+ "version": "1.2.16",
4
4
  "description": "A RESP2 server with practical Redis compatibility, backed by SQLite",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -158,11 +158,13 @@ export function dispatch(engine, argv, context) {
158
158
  }
159
159
  const cmd = (Buffer.isBuffer(argv[0]) ? argv[0].toString('utf8') : String(argv[0])).toUpperCase();
160
160
  const args = argv.slice(1);
161
+ const argvStrings = argv.map((b) => (Buffer.isBuffer(b) ? b.toString('utf8') : String(b)));
161
162
  const handler = HANDLERS.get(cmd);
162
163
  if (!handler) {
163
164
  context?.onUnknownCommand?.({
164
165
  command: cmd,
165
166
  argsCount: args.length,
167
+ argv: argvStrings ?? [cmd],
166
168
  clientAddress: context.clientAddress ?? '',
167
169
  connectionId: context.connectionId ?? 0,
168
170
  });
@@ -175,6 +177,7 @@ export function dispatch(engine, argv, context) {
175
177
  context?.onCommandError?.({
176
178
  command: cmd,
177
179
  error: result.error,
180
+ argv: argvStrings ?? [cmd],
178
181
  clientAddress: context.clientAddress ?? '',
179
182
  connectionId: context.connectionId ?? 0,
180
183
  });
@@ -188,6 +191,7 @@ export function dispatch(engine, argv, context) {
188
191
  context?.onCommandError?.({
189
192
  command: cmd,
190
193
  error: errorMsg,
194
+ argv: argvStrings ?? [cmd],
191
195
  clientAddress: context.clientAddress ?? '',
192
196
  connectionId: context.connectionId ?? 0,
193
197
  });
package/src/embed.js CHANGED
@@ -21,8 +21,8 @@ export { handleConnection, createEngine, openDb };
21
21
  * All hooks are optional. Called with plain objects; do not mutate.
22
22
  *
23
23
  * @typedef {object} RESPliteHooks
24
- * @property {(payload: { command: string, argsCount: number, clientAddress: string, connectionId: number }) => void} [onUnknownCommand] Invoked when the client sends a command not implemented by RESPLite.
25
- * @property {(payload: { command: string, error: string, clientAddress: string, connectionId: number }) => void} [onCommandError] Invoked when a command handler throws or returns an error (e.g. WRONGTYPE, invalid args).
24
+ * @property {(payload: { command: string, argsCount: number, argv: string[], clientAddress: string, connectionId: number }) => void} [onUnknownCommand] Invoked when the client sends a command not implemented by RESPLite. `argv` is the full command line as strings (e.g. `['CLIENT','LIST']`) for logging.
25
+ * @property {(payload: { command: string, error: string, argv: string[], clientAddress: string, connectionId: number }) => void} [onCommandError] Invoked when a command handler throws or returns an error (e.g. WRONGTYPE, invalid args). `argv` is the full command line as strings for logging.
26
26
  * @property {(payload: { error: Error, clientAddress: string, connectionId: number }) => void} [onSocketError] Invoked when a connection socket emits an error (e.g. ECONNRESET).
27
27
  */
28
28