Let developers to call JS methods on limited JS objects
See original GitHub issueIs your feature request related to a problem? If yes, please describe the problem.
It would be great if we could pass over some libraries - take the lodash
to AskQL and let the developers use all the functions provided, without the need to pack every call with a painstakingly created resource (current case). It could be pretty much useful for using the external services APIs like commercetools sdk
or ORMs generated from tools like Prisma
To keep it safe we can let call just the top-level functions, or add whitelisting + only on the explicitly passed resources like:
const vmContext = {
customResources: [
"lodash": jsModuleInterop(_, ["sort", "unique"])
]
where the jsModuleInterop
is a wrapper over the JS object accepting the object (in this case _
- lodash module, plus a whitelist of methods)
Issue Analytics
- State:
- Created 2 years ago
- Comments:9
Top Results From Across the Web
Functions - JavaScript - MDN Web Docs
In JavaScript, functions are first-class objects, because they can have properties and methods just like any other object.
Read more >The 10 Most Common JavaScript Issues Developers Face
JavaScript Issue #8: Creating Incorrect References to Instance Methods. Let's define a simple object, and create an instance of it, as follows:
Read more >The Secret Life of Objects :: Eloquent JavaScript
Usually a method needs to do something with the object it was called on. When a function is called as a method—looked up...
Read more >Method vs Functions, and other questions - javascript
So it could happen that a function A, being an object, has properties and methods, one of which happens to be another function...
Read more >JavaScript best practices - W3C Wiki
Call things by their name — easy, short and readable variable and function names ... Furthermore, not every JavaScript developer is proficient or...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@pkarw seems like this can be done in user space with a resource factory that accepts an object, for example:
The design decision with AskQL was to have a separate computing environment from JavaScript (or any other host programming language) and therefore it would be troublesome to do a direct linking. All callable host methods would need to go through an explicit wrapper which allows for security measures. With the method above it perhaps becomes easier to add multiple resources at the same time.
Although, for full support of what you’re asking for with namespaces would need to solve https://github.com/CatchTheTornado/askql/issues/579 first.
Perfect fit @mhagmajer. Thanks!