-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.js
executable file
·96 lines (73 loc) · 2.95 KB
/
client.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/* client.js
---------
Licence
*/
module.exports = function client_handler( source, module, options ) {
'use strict';
var version = '0.1'
, rs = source.namespace()
, RS = rs.RS
, log = RS.log.bind( null, 'amadeus client.js version', version )
;
log( 'loaded' );
module.client.handler = client;
function client( source, that, options ) {
var rs = source.namespace()
, client = that.socket
, socket = client.socket
, sid = socket.sid
;
log( 'new client, sid:', sid, ' - id:', socket.id, ' - socket.handshake:', socket.handshake );
// ------------------------------------------------------------------------------------------
// All login strategies
// ------------------------------------------------------------------------------------------
var all_login_strategies = source
.flow( 'login_strategies', { name: 'all_login_strategies' } )
.set() // workaround to never terminating fetch aka blank page of death
;
// ------------------------------------------------------------------------------------------
// Authenticated User
// ------------------------------------------------------------------------------------------
// User session from sid
var user_session = source.filter( [ { flow: 'user_sessions', id: sid } ] );
// User provider from authenticated user session' user id
var user_provider_by_profile_id = source
.filter_pick( user_session, { flow: 'users_providers', id: '.user_id' },
{ greedy: true, name: 'user_provider_by_profile_id' }
)
.set()
;
// Authenticated user
var authenticated_user_by_user_id = user_provider_by_profile_id
.pick( { flow: 'users', id: '.user_id' }, { name: 'authenticated_user_by_user_id' } )
;
// Authenticated user profile
var user_profile = source
.filter( authenticated_user_by_user_id )
.set()
// ToDo: rename "profile" dataflow into "authenticated_user"
.set_flow( 'profile', { name: 'user_profile' } )
;
// ------------------------------------------------------------------------------------------
// Write authorizations
// ------------------------------------------------------------------------------------------
// can write
var can_write = authenticated_user_by_user_id
.pick( { flow: 'sequencer', id: '.id' } )
;
return rs
.union( [
all_login_strategies
, user_profile
, source.flow( 'sequencer' )
, source.flow( 'tracks' )
, source.flow( 'amadeus_beats' )
] )
// .trace( 'client read', { all: true } )
.through( client )
// filter client output by write authorizations
.filter( can_write, { name: 'can_write-' + sid } )
// .trace( 'through client', { all: true } )
;
} // client()
}; // module.exports