moleculerjs / moleculer-repl

REPL module for Moleculer framework
http://moleculer.services/docs/moleculer-repl.html
MIT License
27 stars 25 forks source link

Parameters not passed as string #54

Closed SimonVillage closed 2 years ago

SimonVillage commented 3 years ago
mol $ call user.create --phone "+1111111" --passcode "0033"
>> Call 'user.create' with params: { phone: 1111111, passcode: 33 }

however, when passing as json it works.

mol $ call user.create '{"phone": "+ 1111111", "passcode": "0033"}'
>> Call 'user.create' with params: { phone: '+ 1111111', passcode: '0033' }
AndreMaz commented 3 years ago

Hi @SimonHausdorf thanks for reporting the issue. It's related to the https://github.com/moleculerjs/moleculer-repl/issues/47

The issue is caused by vorpal, a dependency lib that we're using, and unfortunately it's no longer maintained. We are aware of vorpal's limitations and we're (slowly :sweat_smile:) migrating to another lib https://github.com/moleculerjs/moleculer-repl/issues/48

Still, I'll try to explain the issue: In the first example the params are being parsed by vorpal, so the handler (moleculer-repl logic) already receives strings as numbers

https://github.com/moleculerjs/moleculer-repl/blob/04b15a43c1321f176d74962ffb4042ebbc3fe715/src/commands/call.js#L12-L15

Here are the args passed to the handler:

// call greeter.hello --phone "+1111111" --passcode "0033"
{
  options: { phone: 1111111, passcode: 33 },
  actionName: 'greeter.hello',
  rawCommand: 'call greeter.hello --phone "+1111111" --passcode "0033"'
}

In the second example the args look like this:

// call greeter.hello '{"phone": "+ 1111111", "passcode": "0033"}'
{
  options: {},
  actionName: 'greeter.hello',
  jsonParams: '{"phone": "+ 1111111", "passcode": "0033"}',
  rawCommand: `call greeter.hello '{"phone": "+ 1111111", "passcode": "0033"}'`
}

and, in this case, the parsing is handled on our side https://github.com/moleculerjs/moleculer-repl/blob/04b15a43c1321f176d74962ffb4042ebbc3fe715/src/commands/call.js#L18