serverless / template

Compose & provision a collection of Serverless Components
https://serverless.com
Apache License 2.0
10 stars 6 forks source link

Template component instance has broken property access #12

Open medikoo opened 4 years ago

medikoo commented 4 years ago

Access of any core property (as hasOwnProperty) or not existing property returns a method as generated by createCustomMethodHandler

Screenshot 2019-10-28 at 12 44 03

This may turn nasty, when we pass such object to any generic util, or if any developer decides to handle it in some outer module.

It's caused by optimistic Proxy setup: https://github.com/serverless/template/blob/fdc1924136d13e06200917cced8227de53b6d2b3/serverless.js#L31

eahefnawy commented 4 years ago

Interesting. @Pavel910 what you think of this?

Pavel910 commented 4 years ago

@eahefnawy yeah, it is problem unfortunately :( Without this crazy Proxy thing, when the CLI tries to fetch a custom method on a Template instance - it will fail.

I totally agree this Proxy thing is far from ideal. Since Template is so baked in at the CLI level, maybe it should have something like hasMethod(method) and executeMethod(method) which would be called by CLI? Then we could remove this Proxy voodoo. it would only require a small change to the CLI in case of a Template component, and a small addition to Template component only, and the Proxy thing would be gone.

Also, I suggest maybe we should remove this custom method feature until better times.