Fun fact: You can convert JavaScript arrow functions to strings and extract the AST (abstract syntax tree) using JSEP.
Suppose you made an ORM that worked like this:
const s = entity
.filter(r => r.id == 9)
.map(r => r.id + 1)
let res = await s.execute()
The execute() function would pick apart the chain, convert filter() to an SQL WHERE clause and map() to a SELECT statement and combine them into:
SELECT id + 1 FROM entity WHERE entity.id = 9
Example screenshot from Node REPL: