moleculerjs / moleculer-repl

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

Unable to pass meta-data when using --load option #41

Closed abdavid closed 4 years ago

abdavid commented 4 years ago

https://github.com/moleculerjs/moleculer-repl/blob/e78ee19f831fdd85fc8e6783534db4e3f80c2cb7/src/commands/call.js#L127

I also tried adding meta to the params file, and looking at the code for the call command, it does not look like meta is supported when loading params from file.

icebob commented 4 years ago

I've just released 0.6.4 which supports defining meta keys with #.

E.g:

moleculer λ call greeter.echo --load test.json --#user John

The user: "John" will be placed into the ctx.meta.

ujwal-setlur commented 3 years ago

What if the meta object is more complicated than a simple key/value pair? In my services, I pass in an authentication object which is relatively nested in meta. Would love to define it in the json file. It would be nice if the file could just have this structure:

{
  "params" : {...},
  "meta": {...}
}
AndreMaz commented 3 years ago

@ujwal-setlur that's not currently possible but definitely doable. If you want to add a support for this you need to add a flag for this kind command over here: https://github.com/moleculerjs/moleculer-repl/blob/3fdf64c0f005cc5cbde47a2efac9a975652a110f/src/commands/call.js#L132-L144

and then in the actual handler add the parsing logic. For example, this is how params are currently being loaded from a file:

https://github.com/moleculerjs/moleculer-repl/blob/3fdf64c0f005cc5cbde47a2efac9a975652a110f/src/commands/call.js#L52-L66

A PR with this would be nice :slightly_smiling_face:

AndreMaz commented 2 years ago

What if the meta object is more complicated than a simple key/value pair? In my services, I pass in an authentication object which is relatively nested in meta. Would love to define it in the json file. It would be nice if the file could just have this structure:

{
  "params" : {...},
  "meta": {...}
}

@ujwal-setlur Added in https://github.com/moleculerjs/moleculer-repl/pull/61