ermouth / couch-photon

An alternative CouchDB admin panel
MIT License
87 stars 12 forks source link

Views are often not recognised #17

Closed ondra-novak closed 5 years ago

ondra-novak commented 5 years ago

Photon 1.3 is not able to recognise views from the design document if they are slightly different than usual. For example following map function is not recognised as view

(function(doc){
    if (doc.tags && Array.isArray(doc.tags)) {
        doc.tags.forEach(function(x) {
            emit(x);
        })
    }
})

That because the function starts with an open bracket. Why? That because my JS editor doesn't understand to function declaration without a name - "function(doc) {}" is syntax error, but "(function(doc) {})" is OK and also CouchDB have no problem with such format.

However, my opinion is, that brackets are not the real problem. I often write scripts in other language than Javascript. I have C++ compiler for scripts as well (see my project ondra-novak/couchcpp). There are also other languages for writing views around (python for example, or erlang can be used as well)

The correct fix of this issue is to remove detection of the type of the script in the function "GetViews" and parse the design document correctly according to specification.

ermouth commented 5 years ago

Thanks for pointing out, issue with ()-wrapped JS function is fixed now.

other languages for writing views around (python for example, or erlang can be used as well)

Erlang is more or less validly detected, as for Python – probably Couch+Python exists somewhere, but I never met it, so it would be at least untestable if I decide to add Python.

parse the design document correctly according to specification

I have to decide if the .views branch is a lib or a view, it‘s not so easy as it seems. In general, I need to fully parse source text to decide if I have a function, which leads to inclusion of Uglify or Acorn parser in the bundle to detect only JS. For Erlang things become even more cumbersome.

So I decided to keep bundle small until I get into especially weird corner case.

BTW any other suggestions/ideas about Photon are highly welcomed.