UNPKG

977 BJavaScriptView Raw
1// Generated by CoffeeScript 2.3.1
2(function() {
3 // Reduce the view
4 // ---------------
5
6 // This assumes the view's reducer is `_count`, obviously.
7 var Immutable, count_as_stream, most, view_stream;
8
9 count_as_stream = function(db_uri, app, view, key, detail) {
10 var params;
11 params = {
12 reduce: true
13 };
14 if ((detail != null) && Immutable.List.isList(key)) {
15 detail = parseInt(detail);
16 if (isNaN(detail) || detail < 0) {
17 return most.empty();
18 }
19 params.group_level = key.size + detail;
20 params.startkey = JSON.stringify(key);
21 params.endkey = JSON.stringify(key.concat(Immutable.Repeat(Immutable.Map(), 1)));
22 } else {
23 params.key = JSON.stringify(key);
24 params.group = true;
25 }
26 return view_stream(db_uri, app, view, params);
27 };
28
29 module.exports = count_as_stream;
30
31 view_stream = require('./view-stream');
32
33 most = require('most');
34
35 Immutable = require('immutable');
36
37}).call(this);