Help

Re: How to get around of npm install (pip install) usual scripting practices in context of AT Script-BLOCK?

2640 1
cancel
Showing results for 
Search instead for 
Did you mean: 

Back to Script-Block,
I have recent memories of very regular python practices like:

  • creating an environment (VENV);
  • PIP install a library of my choice inside this VENV;
  • importing that library into my python code;
  • using it in my python code so I don’t have to rewrite it myself!
    My python is a bit in the fridge in favor of airtable Script-Block.
    Admitting that you can’t use DOM-Manipulation js code, I nevertheless wish to call one or the other available js Code Git by calling it from my own js code which must run in this block.
    Please read on to see what I imagine doing like this.
    Let’s suppose I would have got the RAW js code from a small library called dspmath.js or dspmath.min.js which would not call any dependencies.
    (this case is purely imaginary for the moment.)
    Let’s suppose that I didn’t steal this code and that I intend to use it under the conditions allowed by its rightful owner.
    Suppose that I plan to copy it within my code, preferably in a minified version so as not to be too cumbersome.
  • Where to place it?
  • Which syntax to use?
  • How to call it, use it if you prefer?
    What are the pitfalls already encountered in your Use-Cases, to avoid absolutely when you start in this practice?
    Take your time if you have the possibility to help me a little because I am not in a hurry: I took my precautions not to write these questions when I would already be with my nose against the wall.
    Thank you very much for taking the time to read me.
    olπ
5 Replies 5

I think you are conflating server-side with client-side.

Think of Script Blocks as client-side script running in the browser. In contrast Custom Blocks are server-bound; they are literally installed much like a server plugin would be installed into Apache, or ElasticSearch. As such, you will not soon see an ability to use NPM or NodeJS packages in Script Blocks.

Despite your recollection of a Python development environment on your PC, it is your PC that is playing the role of server. You install the scripting engine, then embellish it with packages, and then you execute the code. NodeJS works much the same and blends nicely when developing Custom Blocks on your local system and which can be deployed for use in Airtable.

In some cases you can use other script libraries, especially minified since there’s a ceiling on the size of script block code. You would just include it at the bottom of the block. How you execute it is dependent upon each library.

Certainly, it would be nice if Script Blocks could include other libraries, but I suspect Airtable is cautious about this because all sorts of javascript sanitization issues arise the instant they open this up to support external library inclusions. BTW - code sanitization is precisely why they haven’t opened access to the DOM.

Best advice - unless your script blocks are simple utilities with the primary intent of manipulating data, best you move over to custom blocks to meet your development requorements.

Sorry @Bill.French,
I’d like to think that I’m not at that point anymore, but I tried to compact my words by writing in English, which is not my mother language, to the point of making this confusion appear in what I published.

Absolutely true!

Your explanations clarify me better on the role of Custom Block versus Script Block!
I will certainly seriously come back this Custom Block step, but I have not yet entered very deeply into it.

It still appears to me as a big challenge to raise because if I had well understood some previous readings in this section, the entirety of my Script (for Script-Block) is considered a Function ?
So I should understand how to “Functionalize” a whole external js code which was not necessarily designed this way ?

I very much appreciate your interventions here, your help.

olπ

Well, that’s difficult to assess because every library is designed differently. Some are function libraries and others may be class libraries. I think you have to assess these on a case-by-case basis and build your own wrappers or modify the library itself to get it to work in a script block.

But to be clear, most external libraries are likely too big to run in script blocks anyway, so if you have a deep need or dependence on them for your scripting solutions, it’s probably wise to move into a full-fledge development approach using Custom Blocks.

No. A script block is a script that may (or may not) contain functions; it is simply a program that starts on the first line and executes thereafter. It’s important to make the distraction that like other scripting environments for the web, it is a non-blocking script model which necessitates careful use of await and other asynchronous underpinnings.

In the meantime I remembered the name “Somehats” and found out what I would refer to when writing this.
But maybe I misinterpreted that thread ?

I agree.
Thank you very much,
olπ

Yes - that’s a very good article.