isomorfeus-transport 1.0.0.zeta11 → 1.0.0.zeta12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4dd43b6af7e9c4592787be224ebcf05ede88f7169098cd773aa2ad2c5f314a1d
4
- data.tar.gz: 4902ffccbc569314da2b83dbeee8422b3cad7d8a62ca94de6fdeb4c0d069f110
3
+ metadata.gz: 429764404614628b8b9f1c62d36a496b57e173dc5c67720f4ba8a07fdac182d8
4
+ data.tar.gz: 8d125f4501ea5ebbbe32112a77e8a6163907e9fd252e9dbf29f4599fc81e3613
5
5
  SHA512:
6
- metadata.gz: 7f6570f7548f423cd6782e8bc3ea9574dc4fb0e63e0e7051a0c50f896aeba297bea40bfe2c3d448c30814235b8c4e66a5bf612e3d909d60c2320910e074fdf8f
7
- data.tar.gz: c7be8c4efbb79221f4215a3734d40fd731710fdec8579ad3cad18db593cf2eef2eccc673c60697666afd50cb825c8b57b6517b91e0e2db2d8aa068525e0efc3a
6
+ metadata.gz: 3ef22091cda95389354afd86d0131cb6395bc5d8207f8b310131063c2b2be4d29ea3bf224d702e4c32b9abba981646821ae45dcf98998a2f7ce9525ee27e2da3
7
+ data.tar.gz: 16395e5e7b942a3317cdacb114f03d97269d2f695dcc1d8b35fadf98acd309bc39e1afdff5551eecd93a43effb22537966d5ebe5fff288e617c08e62b0fc11e6
data/README.md CHANGED
@@ -32,14 +32,16 @@ Server only:
32
32
 
33
33
  ## Authentication
34
34
 
35
- For authentication in isomorfeus there is a class `Anonymous`, so whenever no user is logged in, the anonymous user is passed on to operations or data loads. In my opinion it is more true than no user (nil), because in fact there probably is a user, just the user is unknown. The Anonymous user has a default policy that denies everything, the user will respond to .authorized?(whatever) always with false by default.
35
+ For authentication in isomorfeus there is a class `Anonymous`, so whenever no user is logged in, the anonymous user is passed on to operations
36
+ or data loads. In my opinion it is more true than no user (nil), because in fact there probably is a user, just the user is unknown.
37
+ The Anonymous user has a default policy that denies everything, the user will respond to .authorized?(whatever) always with false by default.
36
38
  Of course, the developer can add a Policy easily, to allow certain operations or data loads, or whatever or everything:
37
39
  ```ruby
38
- class MyAnonymousPolicy < LucidPolicy::Base
39
- policy_for Anonymous
40
+ class AnonymousPolicy < LucidPolicy::Base
40
41
  allow all
41
42
  end
42
43
  ```
44
+ For more information about policy see [the policy docs](https://github.com/isomorfeus/isomorfeus-project/blob/master/ruby/isomorfeus-policy/README.md).
43
45
 
44
46
  A class representing a user should be a LucidNode and include LucidAuthentication::Mixin:
45
47
  ```ruby
@@ -50,7 +50,7 @@ else
50
50
  Opal.append_path(__dir__.untaint) unless Opal.paths.include?(__dir__.untaint)
51
51
 
52
52
  %w[channels handlers server].each do |dir|
53
- path = File.expand_path(File.join('isomorfeus', dir))
53
+ path = File.expand_path(File.join('app', dir))
54
54
  if Dir.exist?(path)
55
55
  Isomorfeus.zeitwerk.push_dir(path)
56
56
  end
@@ -5,12 +5,13 @@ module Isomorfeus
5
5
  attr_accessor :socket
6
6
 
7
7
  def delay(ms = 1000, &block)
8
- `setTimeout(#{block.to_n}, ms)`
8
+ `setTimeout(#{block.to_n}, #{ms})`
9
9
  end
10
10
 
11
11
  def init
12
12
  @requests_in_progress = { requests: {}, agent_ids: {} }
13
13
  @socket = nil
14
+ @initialized = false
14
15
  promise_connect if Isomorfeus.on_browser?
15
16
  true
16
17
  end
@@ -31,7 +32,7 @@ module Isomorfeus
31
32
  @socket = Isomorfeus::Transport::Websocket.new(ws_url)
32
33
  @socket.on_error do
33
34
  @socket.close
34
- delay do
35
+ delay 1000 do
35
36
  Isomorfeus::Transport.promise_connect
36
37
  end
37
38
  end
@@ -40,15 +41,22 @@ module Isomorfeus
40
41
  Isomorfeus::Transport::ClientProcessor.process(json_hash)
41
42
  end
42
43
  @socket.on_open do |event|
43
- init_promises = []
44
- Isomorfeus.transport_init_class_names.each do |constant|
45
- result = constant.constantize.send(:init)
46
- init_promises << result if result.class == Promise
47
- end
48
- if init_promises.size > 0
49
- Promise.when(*init_promises).then { promise.resolve(true) }
50
- else
44
+ if @initialized
45
+ requests_in_progress[:requests].each_key do |request|
46
+ agent = get_agent_for_request_in_progress(request)
47
+ promise_send_request(request) if agent && !agent.sent
48
+ end
51
49
  promise.resolve(true)
50
+ else
51
+ @initialized = true
52
+ init_promises = []
53
+ Isomorfeus.transport_init_class_names.each do |constant|
54
+ result = constant.constantize.send(:init)
55
+ init_promises << result if result.class == Promise
56
+ end
57
+ if init_promises.size > 0
58
+ Promise.when(*init_promises).then { promise.resolve(true) }
59
+ end
52
60
  end
53
61
  end
54
62
  promise
@@ -75,10 +83,12 @@ module Isomorfeus
75
83
  end
76
84
 
77
85
  def promise_send_request(request, &block)
78
- if request_in_progress?(request)
79
- agent = get_agent_for_request_in_progress(request)
80
- else
81
- agent = Isomorfeus::Transport::RequestAgent.new(request)
86
+ agent = if request_in_progress?(request)
87
+ get_agent_for_request_in_progress(request)
88
+ else
89
+ Isomorfeus::Transport::RequestAgent.new(request)
90
+ end
91
+ unless agent.sent
82
92
  if block_given?
83
93
  agent.promise.then do |response|
84
94
  block.call(response)
@@ -86,10 +96,18 @@ module Isomorfeus
86
96
  end
87
97
  register_request_in_progress(request, agent.id)
88
98
  raise 'No socket!' unless @socket
89
- @socket.send(`JSON.stringify(#{{request: { agent_ids: { agent.id => request }}}.to_n})`)
90
- delay(Isomorfeus.on_ssr? ? 8000 : 20000) do
91
- unless agent.promise.realized?
92
- agent.promise.reject({agent_response: { error: 'Request timeout!' }, full_response: {}})
99
+ begin
100
+ @socket.send(`JSON.stringify(#{{request: { agent_ids: { agent.id => request }}}.to_n})`)
101
+ agent.sent = true
102
+ delay(Isomorfeus.on_ssr? ? 8000 : 20000) do
103
+ unless agent.promise.realized?
104
+ agent.promise.reject({agent_response: { error: 'Request timeout!' }, full_response: {}})
105
+ end
106
+ end
107
+ rescue
108
+ @socket.close
109
+ delay 5000 do
110
+ Isomorfeus::Transport.promise_connect
93
111
  end
94
112
  end
95
113
  end
@@ -17,6 +17,7 @@ module Isomorfeus
17
17
  attr_accessor :result
18
18
  attr_accessor :response
19
19
  attr_accessor :full_response
20
+ attr_accessor :sent
20
21
  attr_reader :id
21
22
  attr_reader :promise
22
23
  attr_reader :request
@@ -26,7 +27,8 @@ module Isomorfeus
26
27
  self.class.agents[@id] = self
27
28
  @promise = Promise.new
28
29
  @request = request
30
+ @sent = false
29
31
  end
30
32
  end
31
33
  end
32
- end
34
+ end
@@ -24,9 +24,7 @@ module Isomorfeus
24
24
  response_agent.error = { error: { handler_class_name => 'No such handler!'}}
25
25
  end
26
26
  rescue Exception => e
27
- response_agent.error = if Isomorfeus.production? then { error: { handler_class_name => 'No such handler!'}}
28
- else { response: { error: "#{handler_class_name}: #{e.message}\n#{e.backtrace.join("\n")}" }}
29
- end
27
+ response_agent.error = { response: { error: "#{handler_class_name}: #{e.message}\n#{e.backtrace.join("\n")}" }}
30
28
  end
31
29
  end
32
30
  end
@@ -52,9 +50,7 @@ module Isomorfeus
52
50
  rescue Exception => e
53
51
  response_agent = OpenStruct.new
54
52
  response_agent_array << response_agent
55
- response_agent.result = if Isomorfeus.production? then { response: { error: 'No such thing!' }}
56
- else { response: { error: "Isomorfeus::Transport::ServerProcessor: #{e.message}\n#{e.backtrace.join("\n")}" }}
57
- end
53
+ response_agent.result = { response: { error: "Isomorfeus::Transport::ServerProcessor: #{e.message}\n#{e.backtrace.join("\n")}" }}
58
54
  end
59
55
  elsif request.key?('subscribe') && request['subscribe'].key?('agent_ids')
60
56
  begin
@@ -75,9 +71,7 @@ module Isomorfeus
75
71
  response_agent.error = { error: "No such thing!"}
76
72
  end
77
73
  rescue Exception => e
78
- response_agent.error = if Isomorfeus.production? then { error: 'No such thing!' }
79
- else { error: "Isomorfeus::Transport::ServerProcessor: #{e.message}\n#{e.backtrace.join("\n")}" }
80
- end
74
+ response_agent.error = { error: "Isomorfeus::Transport::ServerProcessor: #{e.message}\n#{e.backtrace.join("\n")}" }
81
75
  end
82
76
  elsif request.key?('unsubscribe') && request['unsubscribe'].key?('agent_ids')
83
77
  begin
@@ -98,10 +92,10 @@ module Isomorfeus
98
92
  response_agent.error = { error: 'No such thing!'}
99
93
  end
100
94
  rescue Exception => e
101
- response_agent.error = if Isomorfeus.production? then { error: 'No such thing!' }
102
- else { error: "Isomorfeus::Transport::ServerProcessor: #{e.message}\n#{e.backtrace.join("\n")}" }
103
- end
95
+ response_agent.error = { error: "Isomorfeus::Transport::ServerProcessor: #{e.message}\n#{e.backtrace.join("\n")}" }
104
96
  end
97
+ else
98
+ response_agent.error = { error: "No such thing!" }
105
99
  end
106
100
  end
107
101
  end
@@ -1,5 +1,5 @@
1
1
  module Isomorfeus
2
2
  module Transport
3
- VERSION = '1.0.0.zeta11'
3
+ VERSION = '1.0.0.zeta12'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isomorfeus-transport
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.zeta11
4
+ version: 1.0.0.zeta12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Biedermann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-27 00:00:00.000000000 Z
11
+ date: 2020-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -72,42 +72,42 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 4.0.16
75
+ version: 4.0.17
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 4.0.16
82
+ version: 4.0.17
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: isomorfeus-react
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: 16.12.6
89
+ version: 16.12.9
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
- version: 16.12.6
96
+ version: 16.12.9
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: isomorfeus-policy
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - '='
102
102
  - !ruby/object:Gem::Version
103
- version: 1.0.0.zeta11
103
+ version: 1.0.0.zeta12
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - '='
109
109
  - !ruby/object:Gem::Version
110
- version: 1.0.0.zeta11
110
+ version: 1.0.0.zeta12
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: websocket-driver
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -128,14 +128,14 @@ dependencies:
128
128
  requirements:
129
129
  - - '='
130
130
  - !ruby/object:Gem::Version
131
- version: 1.0.0.zeta11
131
+ version: 1.0.0.zeta12
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - '='
137
137
  - !ruby/object:Gem::Version
138
- version: 1.0.0.zeta11
138
+ version: 1.0.0.zeta12
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: opal-webpack-loader
141
141
  requirement: !ruby/object:Gem::Requirement