Again, this is just a proof of concept.
just to demonstrate that it is possible to take Javascript code and run it in a Coda document.
only a tiny subset of the language is covered in this demo.
later i will expand it to cover most of the useful statement types and to provide some syntax checking and error messages etc.
Looking at your doc, Iâm wondering â do you not have to use $$[] references in your constructed action anymore? I mean, is it sufficient now to just {"type":"PendingEvaluation","formula":"CUSTOMERS.nth(c).ORDERS.formulamap(...)"}?
the clf intrepreter only needs the identifiers in text. it returns quite useful error messages if the cfl is ill-formed.
i am sure there is a performance hit, the $$[âŚ] form is presumably faster.
think of it as an eval() function ala javascriptâŚ
not as optimized as compiled code, but the late-binding is extremely useful.
the location: nodes which give the table, column and row info for the formula must be given as grid references so the intrepreter knows the context, so that column names and thisRow can be intrepreted correctly.
i suspect that we will now be able to find MANY powerful uses of this variation of the Black Magic technique
Oh cool, and I was painfully constructing each and every $$[] in my dedupe template⌠twice, because I first created it with the new editor and could not make into a template.
Hey @Agile_Dynamics ,
I was taking a look at your demo doc, but it is view and non-copy, so there isnât all that much to see. Is is intentionally shared this way?
Greetings,
Joost
No copy and view onlyâŚ
To look at the formulas, I would like the no-copy option to be copy, makes it easier to look at the details.
Not sure how that is going to work for people that donât have the pack option yet (like me )
and this has nothing to do with packs⌠its all pure coda formula language
but
it does use hidden, unsupported functions like _Merge(), _Deref_Object() and _Noop()
which is why i am doing a bigger doc to explain the dependencies and cotchaâs
for example, typing code into a table cell will do crazy things with certain characters (eg. there are SIX types of quotation characters) even if you set the format to âcode blockâ. the RegexReplace() function needed to fix all this is a nightmare and still a w.i.p
i am also working on a proper lexical analyser to at least ensure the syntax is correct and that the cfl it emits is reasonably correct.
so meantime i just pushed out this demo doc ahead of time before its production ready because i think the tricks it uses will be of use to other makers
its now copyable and i put a copy doc button at the top
I just got done looking in dept at your doc: very impressive, you put a lot of effort into making this work and to âfinishâ it will take a lot of extra effort.
Ha, this is neat. I tried to do a pack with return new Function(input1)(input2) but dynamic code evaluation is prohibited by the compiler so I wasnât able to. I can see youâre getting around that by using CLF to parse it somehow? Gonna dig into your code a bit more to see where the secret sauce is, how do you actually generate executable code in your pack?
i am building on the âBlack Magicâ hack from @Paul_Danyliuk (and others)
i extract the inner JSON of an existing button, modify it to insert the text of the code i want to execute to get a new Action which can be executed using RunActions().
so no pack involved so far. but it uses hidden unsupported formulas, and will fail if coda changes any of the many details of how buttons or actions are managed.
i do want to encapsulate this into a pack to minimise such risks, improve performance, provide syntax and error checking etc
however, the reason the eval() and execute() functions of javascript are NOT provided for packs is to ensure security. dont want anyone inserting dodgy unsafe or malignant code via that trojan horse!
BUT
this technique only generates native coda formula code that will run WITHIN the owners own document. so it cannot do anything nasty that the user couldnt do with bog-standard formulas anyway.
as well as being a fun thing to do, my clients have TONS of existing BASIC and JS code snippets in their thousands of spreadsheets (excel and google sheets) and lots of experience writing automations in those languages.
so i am on a âGreat Questâ to find a way to migrate such workflows without having to re-write every line of code.
migrating native excel formulas to coda would help as well. changing the A99 cell refs into column names etc, so its gonna be a long and facinating Quest
if you know anyone looking to migrate existing workflows from excel, access, sheets or notion, please let me know. i have lots of tools to help that process
Where can I learn about this so-called âBlack Magicâ? Are these just the undocumented APIs? I can see youâve got some way to extract JSON from Coda valuesâŚ
I found a JS interpreter written in JS and included itâs whole code within the Pack (because Iâm too lazy to go the CLI way and do it with modules)
I did a very crude job making it work (basically slapped a lot of : any to shut up TSLint and also removed anything around web workers APIs) so it stopped working reliably lol. Thatâs why I never shared it or published it⌠or took any money for it