Recompiling JS in the arangodb codebase? (trying to hack sth into Foxx)

79 views Asked by At

I've made a change to a .js file in the arangodb codebase and did a make clean && make and restarted arangod, but the change doesn't seem to be picked up. How do I make sure the change is activated?

The changed file was: js/server/modules/org/arangodb/foxx/query.js


The docs chapter that brought me to this idea is https://github.com/arangodb/arangodb/blob/40ea11ab45b80cd38a9db7b7cab09b8bcc2cd43d/Documentation/Books/Users/Foxx/FoxxRepository.mdpp#L18 which, btw, doesn't show how to pass arguments to the query and it references a 'chapter on Foxx Queries' I couldn't find.


Ultimately, the goal is to pass arguments not only to the query but also to the transform function that is called. The diff is

diff --git a/js/server/modules/org/arangodb/foxx/query.js b/js/server/modules/org/arangodb/foxx/query.js
index 49e320c..ac37f34 100644
--- a/js/server/modules/org/arangodb/foxx/query.js
+++ b/js/server/modules/org/arangodb/foxx/query.js
@@ -61,7 +61,7 @@ exports.createQuery = function createQuery (cfg) {
     throw new Error('Expected transform to be a function.');
   }
 
-  return function query(vars) {
+  return function query(vars, trArgs) {
     vars = _.extend({}, defaults, vars);
     if (context) {
       _.each(vars, function (value, key) {
@@ -76,6 +76,6 @@ exports.createQuery = function createQuery (cfg) {
         return new Model(data);
       });
     }
-    return transform ? transform(result) : result;
+    return transform ? transform(result, trArgs:) : result;
   };
-};
\ No newline at end of file
+};

The repository would look like this:

(function () {
    "use strict";

    var Foxx    = require("org/arangodb/foxx");
    var Pingers = Foxx.Repository.extend({

        ping: Foxx.createQuery({
            query: "FOR p IN pingers FILTER p._key == @id return p",
            transform: function(items, args) {
                var lang = args.lang;
                for (var i = 0; i < items.length; i++) {
                    var item = items[i];
                    item.name = item.name[lang];
                    item.description = item.description[lang];
                }
                return items;
            }
        }),

    exports.Repository = Pingers;
}());

And the controller:

ctrl.get("/ping", function(req, res) {
    var id = req.param('id');
    var lang = req.param('lang');
    res.json(pingers.ping({id: id}, {lang: lang}));
});
1

There are 1 answers

1
fceller On BEST ANSWER

I should be enough to restart the server. The Javascript files are not pre-compiled and loaded as required.

The line

return transform ? transform(result, trArgs:) : result;

looks suspicious. The ":" after the trArgs is strange. This should raise an error.