1 |
|
2 | (function() {
|
3 |
|
4 |
|
5 | var Immutable, count_as_stream, group_as_stream, most, query_as_stream, range_as_stream, view_as_stream;
|
6 |
|
7 | view_as_stream = function(db_uri, app, view, key) {
|
8 | switch (false) {
|
9 |
|
10 |
|
11 | case !Immutable.Map.isMap(key):
|
12 | switch (false) {
|
13 |
|
14 |
|
15 | case !key.has('level'):
|
16 | return group_as_stream(db_uri, app, view, key.get('level'), key.get('min'), key.get('max')).tap(function(row) {
|
17 | return [row.key, row.value] = [key, row.key];
|
18 | });
|
19 |
|
20 | case !key.has('count'):
|
21 | return count_as_stream(db_uri, app, view, key.get('count'), key.get('detail')).tap(function(row) {
|
22 | if (row.key != null) {
|
23 | return [row.key, row._key] = [key, row.key];
|
24 | } else {
|
25 | return row.key = key;
|
26 | }
|
27 | });
|
28 |
|
29 | case !(key.has('min') || key.has('max')):
|
30 | return range_as_stream(db_uri, app, view, key.get('min'), key.get('max')).tap(function(row) {
|
31 | return [row.key, row._key] = [key, row.key];
|
32 | });
|
33 | default:
|
34 | return most.empty();
|
35 | }
|
36 | break;
|
37 | default:
|
38 |
|
39 | return query_as_stream(db_uri, app, view, key);
|
40 | }
|
41 | };
|
42 |
|
43 | module.exports = view_as_stream;
|
44 |
|
45 | query_as_stream = require('./query');
|
46 |
|
47 | count_as_stream = require('./count');
|
48 |
|
49 | range_as_stream = require('./range');
|
50 |
|
51 | group_as_stream = require('./group');
|
52 |
|
53 | most = require('most');
|
54 |
|
55 | Immutable = require('immutable');
|
56 |
|
57 | }).call(this);
|