UNPKG

2.4 kBJavaScriptView Raw
1// Generated by CoffeeScript 2.3.1
2(function() {
3 // View dispatcher
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 // - Map (JSON object) is used to provide one-time queries. These do not support `changes` streaming.
10 // The `key` field (in the `SUBSCRIBE` message) is used to determine what type of query is performed:
11 case !Immutable.Map.isMap(key):
12 switch (false) {
13 // For `group` queries we send the view's `key` in the `value` field of the message.
14 // For view queries we need to keep the original `key` field (for routing purposes).
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 // For count queries we set the `_key` field to the key generated by the view (the `value` field contains the view's `value`, i.e. the `count`).
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 // For range queries we set the `_key` field to the key generated by the view (the `value` field contains the view's `value`).
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 // - string, List, etc., generate regular view queries (and are subject to `changes` streaming, see `./changes-view`).
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);