How to extend FQL with Javascript

I’ve seen some examples that FQL is extended with Javascript.
I haven’t found any official documentation about it, and I’m not really sure how does it work,

I’m trying to follow OPTION2 from the link above to create a full text index for my collection. What I don’t understand is how does the JS code become part of the Index in Fauna. Is it somehow compiled into something that Fauna can execute and stored on Fauna side?
Just to make sure I understand - this Index becomes part of my DB, no matter where the documents are being created or updated from, right?
Is it possible to create this kind of Index from Fauna dashboard (from the Shell tab or from the Indexes tab) or only from a JS client?

Thanks

Sorry about the silly questions, but I just couldn’t figure this out.

There are FQL libraries for several host languages. These are very thin wrappers on top of a language like javascript, which is used to build FQL with that language, and send it to the database. The Fauna database only works with pure FQL, and does not embed or run the host language inside of itself.

I recommend using a host language and library such as the one available for javascript since it allows you to more easily create reusable and well organized FQL code. It also allows brings syntax highlighting, code formatting, code completion, dependency resolution, and some static error checking with it if you use the library within an editor like vscode.

That being said, everything you can do in javascript you can also accomplish by running FQL commands in Fauna’s dashboard shell, or by creating functions/indexes in their respective places in the dashboard.

The JS is just generating FQL. If we compare this to if you would generate SQL then you would generate a string. Since FQL is actually a collection of JavaScript functions (since strings are evil and not composable), you will use JS to return composed FQL functions instead of returning a string. Examples are here:

This app uses composition extensively as well:
https://docs.fauna.com/fauna/current/start/apps/fwitter