hyper-operation 1.0.alpha1.8 → 1.0.0.lap28

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -7
  3. data/.travis.yml +9 -21
  4. data/CODE_OF_CONDUCT.md +49 -0
  5. data/DOCS-POLICIES.md +582 -0
  6. data/DOCS.md +869 -0
  7. data/Gemfile +1 -5
  8. data/LICENSE.txt +21 -0
  9. data/README.md +77 -0
  10. data/Rakefile +2 -1
  11. data/dciy.toml +3 -0
  12. data/hyper-operation.gemspec +15 -19
  13. data/lib/hyper-operation.rb +6 -10
  14. data/lib/hyper-operation/api.rb +4 -8
  15. data/lib/hyper-operation/boot.rb +2 -3
  16. data/lib/hyper-operation/delay_and_interval.rb +9 -0
  17. data/lib/hyper-operation/engine.rb +2 -2
  18. data/lib/hyper-operation/exception.rb +4 -30
  19. data/lib/hyper-operation/filters/acting_user.rb +1 -1
  20. data/lib/hyper-operation/http.rb +2 -2
  21. data/lib/hyper-operation/promise.rb +2 -32
  22. data/lib/hyper-operation/railway.rb +1 -1
  23. data/lib/hyper-operation/railway/dispatcher.rb +5 -8
  24. data/lib/hyper-operation/railway/params_wrapper.rb +2 -2
  25. data/lib/hyper-operation/railway/run.rb +49 -58
  26. data/lib/hyper-operation/railway/validations.rb +3 -10
  27. data/lib/hyper-operation/server_op.rb +20 -46
  28. data/lib/hyper-operation/transport/action_cable.rb +8 -8
  29. data/lib/hyper-operation/transport/client_drivers.rb +55 -96
  30. data/lib/hyper-operation/transport/connection.rb +136 -58
  31. data/lib/hyper-operation/transport/{hyperstack.rb → hyperloop.rb} +15 -28
  32. data/lib/hyper-operation/transport/{hyperstack_controller.rb → hyperloop_controller.rb} +53 -59
  33. data/lib/hyper-operation/transport/policy.rb +49 -50
  34. data/lib/hyper-operation/version.rb +2 -2
  35. data/lib/sources/{hyperstack → hyperloop}/pusher.js +0 -0
  36. metadata +73 -94
  37. data/lib/hyper-operation/async_sleep.rb +0 -23
  38. data/lib/hyper-operation/transport/connection_adapter/active_record.rb +0 -113
  39. data/lib/hyper-operation/transport/connection_adapter/active_record/auto_create.rb +0 -26
  40. data/lib/hyper-operation/transport/connection_adapter/active_record/connection.rb +0 -47
  41. data/lib/hyper-operation/transport/connection_adapter/active_record/queued_message.rb +0 -42
  42. data/lib/hyper-operation/transport/connection_adapter/redis.rb +0 -94
  43. data/lib/hyper-operation/transport/connection_adapter/redis/connection.rb +0 -85
  44. data/lib/hyper-operation/transport/connection_adapter/redis/queued_message.rb +0 -34
  45. data/lib/hyper-operation/transport/connection_adapter/redis/redis_record.rb +0 -158
  46. data/lib/hyper-operation/transport/policy_diagnostics.rb +0 -106
@@ -1,6 +1,7 @@
1
- module Hyperstack
1
+ module Hyperloop
2
2
  class Operation
3
3
  class Railway
4
+
4
5
  def receivers
5
6
  self.class.receivers
6
7
  end
@@ -8,16 +9,12 @@ module Hyperstack
8
9
  class << self
9
10
  def receivers
10
11
  # use the force: true option so that system code needing to receive
11
- # boot will NOT be erased on the next Hyperstack::Context.reset!
12
- Hyperstack::Context.set_var(self, :@receivers, force: true) { [] }
12
+ # boot will NOT be erased on the next Hyperloop::Context.reset!
13
+ Hyperloop::Context.set_var(self, :@receivers, force: true) { [] }
13
14
  end
14
15
 
15
16
  def add_receiver(&block)
16
- cloned_block = ->(*args, &b) { block.call(*args, &b) }
17
- operation = self
18
- cloned_block.define_singleton_method(:unmount) { operation.receivers.delete(cloned_block) }
19
- receivers << cloned_block
20
- cloned_block
17
+ receivers << block
21
18
  end
22
19
  end
23
20
 
@@ -1,4 +1,4 @@
1
- module Hyperstack
1
+ module Hyperloop
2
2
  class Operation
3
3
  class ParamsWrapper
4
4
 
@@ -119,7 +119,7 @@ module Hyperstack
119
119
  end
120
120
 
121
121
  def self.params_wrapper
122
- Hyperstack::Context.set_var(self, :@params_wrapper) do
122
+ Hyperloop::Context.set_var(self, :@params_wrapper) do
123
123
  if Railway == superclass
124
124
  Class.new(ParamsWrapper)
125
125
  else
@@ -1,16 +1,13 @@
1
- module Hyperstack
1
+ module Hyperloop
2
2
  class Operation
3
3
 
4
4
  class Exit < StandardError
5
5
  attr_reader :state
6
6
  attr_reader :result
7
- def initialize(state, result = nil)
7
+ def initialize(state, result)
8
8
  @state = state
9
9
  @result = result
10
10
  end
11
- def to_s
12
- @state
13
- end
14
11
  end
15
12
 
16
13
  class Railway
@@ -24,7 +21,7 @@ module Hyperstack
24
21
  @tracks ||= []
25
22
  end
26
23
 
27
- def build_tie(tie, args, block)
24
+ def to_opts(tie, args, block)
28
25
  if args.count.zero?
29
26
  { run: block }
30
27
  elsif args[0].is_a?(Hash)
@@ -44,7 +41,7 @@ module Hyperstack
44
41
 
45
42
  [:step, :failed, :async].each do |tie|
46
43
  define_method :"add_#{tie}" do |*args, &block|
47
- tracks << build_tie(tie, args, block)
44
+ tracks << to_opts(tie, args, block)
48
45
  end
49
46
  end
50
47
 
@@ -58,36 +55,44 @@ module Hyperstack
58
55
  end
59
56
 
60
57
  def step(opts)
61
- @promise_chain = @promise_chain
62
- .then { |result| apply(result, :success, opts) }
58
+ if @last_result.is_a? Promise
59
+ @last_result = @last_result.then do |*result|
60
+ @last_result = result
61
+ apply(opts, :in_promise)
62
+ end
63
+ elsif @state == :success
64
+ apply(opts)
65
+ end
63
66
  end
64
67
 
65
68
  def failed(opts)
66
- @promise_chain = @promise_chain
67
- .always do |result|
68
- @state = :failed if @promise_chain.rejected? && @state != :abort
69
- apply(result, :failed, opts)
69
+ if @last_result.is_a? Promise
70
+ @last_result = @last_result.fail do |e|
71
+ @last_result = e
72
+ apply(opts, :in_promise)
73
+ raise @last_result if @last_result.is_a? Exception
74
+ raise e
70
75
  end
76
+ elsif @state == :failed
77
+ apply(opts)
78
+ end
71
79
  end
72
80
 
73
81
  def async(opts)
74
- @promise_chain = @promise_chain_start = Promise.new
75
- @promise_chain.resolve(@last_async_result)
76
- step(opts)
82
+ apply(opts) if @state != :failed
77
83
  end
78
84
 
79
- def apply(result, state, opts)
80
- return result unless @state == state
85
+ def apply(opts, in_promise = nil)
81
86
  if opts[:scope] == :class
82
- args = [@operation, *result]
87
+ args = [@operation, *@last_result]
83
88
  instance = @operation.class
84
89
  else
85
- args = result
90
+ args = @last_result
86
91
  instance = @operation
87
92
  end
88
93
  block = opts[:run]
89
94
  block = instance.method(block) if block.is_a? Symbol
90
- last_result =
95
+ @last_result =
91
96
  if block.arity.zero?
92
97
  instance.instance_exec(&block)
93
98
  elsif args.is_a?(Array) && block.arity == args.count
@@ -95,54 +100,40 @@ module Hyperstack
95
100
  else
96
101
  instance.instance_exec(args, &block)
97
102
  end
98
- @last_async_result = last_result unless last_result.is_a? Promise
99
- last_result
103
+ return @last_result unless @last_result.is_a? Promise
104
+ raise @last_result.error if @last_result.rejected?
105
+ @last_result = @last_result.value if @last_result.resolved?
106
+ @last_result
100
107
  rescue Exit => e
101
- # the promise chain ends with an always block which will process
102
- # any immediate exits by checking the value of @state. All other
103
- # step/failed/async blocks will be skipped because state will not equal
104
- # :succeed or :failed
105
- if e.state == :failed
106
- @state = :abort
107
- # exit via the final always block with the exception
108
- raise e.result.is_a?(Exception) ? e.result : e
109
- else
110
- @state = :succeed
111
- # exit via the final then block with the success value
112
- e.result
113
- end
108
+ @state = e.state
109
+ @last_result = (e.state != :failed || e.result.is_a?(Exception)) ? e.result : e
110
+ raise e
114
111
  rescue Exception => e
115
112
  @state = :failed
116
- raise e
113
+ @last_result = e
114
+ raise e if in_promise
117
115
  end
118
116
 
119
117
  def run
120
- # if @operation.has_errors? || @state
121
- # @last_result ||= ValidationException.new(@operation.instance_variable_get('@errors'))
122
- # # following handles abort out of validation. if state is already set then we are aborting
123
- # # otherwise if state is not set but we have errors then we are failed
124
- # @state ||= :failed
125
- # else
126
- # @state = :success
127
- # end
128
- @state ||= :success
129
- @promise_chain_start = @promise_chain = Promise.new
130
- @promise_chain_start.resolve(@last_result)
131
- tracks.each { |opts| opts[:tie].bind(self).call(opts) } unless @state == :abort
118
+ if @operation.has_errors? || @state
119
+ @last_result ||= ValidationException.new(@operation.instance_variable_get('@errors'))
120
+ return if @state # handles abort out of validation
121
+ @state = :failed
122
+ else
123
+ @state = :success
124
+ end
125
+ tracks.each { |opts| opts[:tie].bind(self).call(opts) }
126
+ rescue Exit
132
127
  end
133
128
 
134
129
  def result
135
- @result ||= @promise_chain.always do |e|
136
- if %i[abort failed].include? @state
137
- if e.is_a? Exception
138
- raise e
139
- else
140
- raise Promise::Fail.new(e)
141
- end
130
+ return @last_result if @last_result.is_a? Promise
131
+ @last_result =
132
+ if @state == :success
133
+ Promise.new.resolve(@last_result)
142
134
  else
143
- e
135
+ Promise.new.reject(@last_result)
144
136
  end
145
- end
146
137
  end
147
138
  end
148
139
  end
@@ -1,4 +1,4 @@
1
- module Hyperstack
1
+ module Hyperloop
2
2
  class Operation
3
3
  class Railway
4
4
 
@@ -28,8 +28,6 @@ module Hyperstack
28
28
  rescue Exit => e
29
29
  raise e unless e.state == :failed
30
30
  add_error(param, symbol, message)
31
- # use a bogus exit state which will skip adding
32
- # a validation error (see catch block in process_validations method)
33
31
  raise Exit.new(:abort_from_add_error, e.result)
34
32
  end
35
33
  end
@@ -49,22 +47,17 @@ module Hyperstack
49
47
  when :failed
50
48
  add_validation_error(i, "param validation #{i+1} aborted")
51
49
  end
52
- @state = :abort
50
+ @state = :failed
53
51
  return # break does not work in Opal
54
52
  rescue AccessViolation => e
55
53
  add_validation_error(i, e)
56
- @state = :abort
54
+ @state = :failed
57
55
  @last_result = e
58
56
  return # break does not work in Opal
59
57
  rescue Exception => e
60
58
  add_validation_error(i, e)
61
59
  end
62
60
  end
63
- ensure
64
- if @operation.has_errors?
65
- @last_result ||= ValidationException.new(@operation.instance_variable_get('@errors'))
66
- @state ||= :failed
67
- end
68
61
  end
69
62
  end
70
63
  end
@@ -1,30 +1,26 @@
1
1
  require 'net/http' unless RUBY_ENGINE == 'opal'
2
2
 
3
- module Hyperstack
3
+ module Hyperloop
4
4
  class ServerOp < Operation
5
5
 
6
6
  class << self
7
- include Hyperstack::Component::IsomorphicHelpers
7
+ include React::IsomorphicHelpers
8
8
 
9
9
  if RUBY_ENGINE == 'opal'
10
10
  if on_opal_client?
11
11
  def run(*args)
12
12
  hash = _Railway.params_wrapper.combine_arg_array(args)
13
13
  hash = serialize_params(hash)
14
- Hyperstack::HTTP.post(
15
- "#{`window.HyperstackEnginePath`}/execute_remote",
16
- payload: {hyperstack_secured_json: {operation: name, params: hash}.to_json},
17
- headers: headers.merge('X-CSRF-Token' => Hyperstack::ClientDrivers.opts[:form_authenticity_token])
14
+ Hyperloop::HTTP.post(
15
+ "#{`window.HyperloopEnginePath`}/execute_remote",
16
+ payload: {json: {operation: name, params: hash}.to_json},
17
+ headers: {'X-CSRF-Token' => Hyperloop::ClientDrivers.opts[:form_authenticity_token] }
18
18
  )
19
19
  .then do |response|
20
20
  deserialize_response response.json[:response]
21
21
  end
22
22
  .fail do |response|
23
- begin
24
- const_get(response.json[:error_class]).new(response.json[:error])
25
- rescue
26
- Exception.new response.json[:error]
27
- end
23
+ Exception.new response.json[:error]
28
24
  end
29
25
  end
30
26
  elsif on_opal_server?
@@ -44,21 +40,19 @@ module Hyperstack
44
40
  isomorphic_method(:internal_iso_run) do |f, klass_name, op_params|
45
41
  f.send_to_server(klass_name, op_params)
46
42
  f.when_on_server {
47
- Hyperstack::ServerOp.run_from_client(:acting_user, controller, klass_name, *op_params)
43
+ Hyperloop::ServerOp.run_from_client(:acting_user, controller, klass_name, *op_params)
48
44
  }
49
45
  end
50
46
 
51
47
  def descendants_map_cache
52
48
  # calling descendants alone may take 10ms in a complex app, so better cache it
53
- @cached_descendants ||= Hyperstack::ServerOp.descendants.map(&:to_s)
49
+ @cached_descendants ||= Hyperloop::ServerOp.descendants.map(&:to_s)
54
50
  end
55
51
 
56
52
  def run_from_client(security_param, controller, operation, params)
57
53
  if Rails.env.production?
58
54
  # in production everything is eager loaded so ServerOp.descendants is filled and can be used to guard the .constantize
59
- unless Hyperstack::ServerOp.descendants_map_cache.include?(operation)
60
- Hyperstack::InternalPolicy.raise_operation_access_violation(:illegal_remote_op_call, "Operation: #{operation} (in production)")
61
- end
55
+ Hyperloop::InternalPolicy.raise_operation_access_violation unless Hyperloop::ServerOp.descendants_map_cache.include?(operation)
62
56
  # however ...
63
57
  else
64
58
  # ... in development things are autoloaded on demand, thus ServerOp.descendants can be empty or partially filled and above guard
@@ -68,17 +62,15 @@ module Hyperstack
68
62
  begin
69
63
  const = Object.const_get(operation)
70
64
  rescue NameError
71
- Hyperstack::InternalPolicy.raise_operation_access_violation(:illegal_remote_op_call, "Operation: #{operation} (const not found)")
72
- end
73
- unless const < Hyperstack::ServerOp
74
- Hyperstack::InternalPolicy.raise_operation_access_violation(:illegal_remote_op_call, "Operation: #{operation} (not a ServerOp subclass)")
65
+ Hyperloop::InternalPolicy.raise_operation_access_violation
75
66
  end
67
+ Hyperloop::InternalPolicy.raise_operation_access_violation unless const < Hyperloop::ServerOp
76
68
  end
77
69
  operation.constantize.class_eval do
78
70
  if _Railway.params_wrapper.method_defined?(:controller)
79
71
  params[:controller] = controller
80
72
  elsif !_Railway.params_wrapper.method_defined?(security_param)
81
- raise AccessViolation.new(:remote_access_not_allowed)
73
+ raise AccessViolation
82
74
  end
83
75
  run(deserialize_params(params))
84
76
  .then { |r| return { json: { response: serialize_response(r) } } }
@@ -88,27 +80,13 @@ module Hyperstack
88
80
  handle_exception(e, operation, params)
89
81
  end
90
82
 
91
- def status(e)
92
- if e.is_a? AccessViolation
93
- 403
94
- elsif e.is_a? Operation::ValidationException
95
- 400
96
- else
97
- 500
98
- end
99
- end
100
-
101
83
  def handle_exception(e, operation, params)
102
- if e.respond_to? :__hyperstack_on_error
103
- params = params.to_h
104
- message = []
105
- message << Pastel.new.red("HYPERSTACK ERROR during #{operation} #{e.inspect}")
106
- params.each { |param, value| message << " #{param} => #{value.inspect.truncate(120, separator: '...')}" }
107
- message << "\n#{e.details}" if e.respond_to? :details
108
- e.__hyperstack_on_error(operation, params, message.join("\n"))
84
+ if defined? ::Rails
85
+ params.delete(:controller)
86
+ ::Rails.logger.debug "\033[0;31;1mERROR: Hyperloop::ServerOp exception caught when running "\
87
+ "#{operation} with params \"#{params}\": #{e}\033[0;30;21m"
109
88
  end
110
-
111
- { json: { error_class: e.class.to_s, error: e}, status: status(e) }
89
+ { json: { error: e }, status: 500 }
112
90
  end
113
91
 
114
92
 
@@ -122,17 +100,13 @@ module Hyperstack
122
100
  end
123
101
  request.body = {
124
102
  operation: name,
125
- params: Hyperstack::Operation::ParamsWrapper.combine_arg_array(args)
103
+ params: Hyperloop::Operation::ParamsWrapper.combine_arg_array(args)
126
104
  }.to_json
127
105
  promise.resolve http.request(request)
128
106
  rescue Exception => e
129
107
  promise.reject e
130
108
  end
131
109
 
132
- def headers
133
- {}
134
- end
135
-
136
110
  def serialize_params(hash)
137
111
  hash
138
112
  end
@@ -174,7 +148,7 @@ module Hyperstack
174
148
  [operation.instance_exec(*context, &regulation)].flatten.compact.uniq.each do |channel|
175
149
  unless operation.instance_variable_get(:@_dispatched_channels).include?(channel)
176
150
  operation.instance_variable_set(:@_dispatched_channels, operation.instance_variable_get(:@_dispatched_channels) << channel)
177
- Hyperstack.dispatch(channel: Hyperstack::InternalPolicy.channel_to_string(channel), operation: operation.class.name, params: serialized_params)
151
+ Hyperloop.dispatch(channel: Hyperloop::InternalPolicy.channel_to_string(channel), operation: operation.class.name, params: serialized_params)
178
152
  end
179
153
  end
180
154
  end
@@ -3,7 +3,7 @@ module ApplicationCable
3
3
  class Connection < ActionCable::Connection::Base; end
4
4
  end
5
5
 
6
- module Hyperstack
6
+ module Hyperloop
7
7
  class ActionCableChannel < ApplicationCable::Channel
8
8
  class << self
9
9
  def subscriptions
@@ -12,28 +12,28 @@ module Hyperstack
12
12
  end
13
13
 
14
14
  def inc_subscription
15
- self.class.subscriptions[params[:hyperstack_channel]] =
16
- self.class.subscriptions[params[:hyperstack_channel]] + 1
15
+ self.class.subscriptions[params[:hyperloop_channel]] =
16
+ self.class.subscriptions[params[:hyperloop_channel]] + 1
17
17
  end
18
18
 
19
19
  def dec_subscription
20
- self.class.subscriptions[params[:hyperstack_channel]] =
21
- self.class.subscriptions[params[:hyperstack_channel]] - 1
20
+ self.class.subscriptions[params[:hyperloop_channel]] =
21
+ self.class.subscriptions[params[:hyperloop_channel]] - 1
22
22
  end
23
23
 
24
24
  def subscribed
25
25
  session_id = params["client_id"]
26
- authorization = Hyperstack.authorization(params["salt"], params["hyperstack_channel"], session_id)
26
+ authorization = Hyperloop.authorization(params["salt"], params["hyperloop_channel"], session_id)
27
27
  if params["authorization"] == authorization
28
28
  inc_subscription
29
- stream_from "hyperstack-#{params[:hyperstack_channel]}"
29
+ stream_from "hyperloop-#{params[:hyperloop_channel]}"
30
30
  else
31
31
  reject
32
32
  end
33
33
  end
34
34
 
35
35
  def unsubscribed
36
- Hyperstack::Connection.disconnect(params[:hyperstack_channel]) if dec_subscription == 0
36
+ Hyperloop::Connection.disconnect(params[:hyperloop_channel]) if dec_subscription == 0
37
37
  end
38
38
  end
39
39
  end
@@ -1,18 +1,14 @@
1
1
  #### this is going to need some refactoring so that HyperMesh can add its methods in here...
2
2
 
3
- module Hyperstack
3
+ module Hyperloop
4
4
  # Client side handling of synchronization messages
5
5
  # When a synchronization message comes in, the client will sync_dispatch
6
6
  # We use ERB to determine the configuration and implement the appropriate
7
7
  # client interface to sync_change or sync_destroy
8
8
 
9
- def self.anti_csrf_token
10
- ClientDrivers.opts[:form_authenticity_token]
11
- end
12
-
13
9
  class Application
14
- extend Component::IsomorphicHelpers::ClassMethods
15
-
10
+ extend React::IsomorphicHelpers::ClassMethods
11
+
16
12
  if on_opal_client?
17
13
  def self.acting_user_id
18
14
  ClientDrivers.opts[:acting_user_id]
@@ -35,41 +31,22 @@ module Hyperstack
35
31
 
36
32
 
37
33
  if RUBY_ENGINE == 'opal'
38
- # Patch in a dummy copy of Model.load in case we are not using models
39
- # this will be defined properly by hyper-model
40
- module Model
41
- def self.load
42
- Promise.new.tap { |promise| promise.resolve(yield) }
43
- end unless respond_to?(:load)
44
- end
45
-
46
34
  def self.connect(*channels)
47
35
  channels.each do |channel|
48
36
  if channel.is_a? Class
49
37
  IncomingBroadcast.connect_to(channel.name)
50
38
  elsif channel.is_a?(String) || channel.is_a?(Array)
51
39
  IncomingBroadcast.connect_to(*channel)
52
- elsif channel.respond_to?(:id)
53
- Hyperstack::Model.load do
54
- channel.id
55
- end.then do |id|
56
- raise "Hyperstack.connect cannot connect to #{channel.inspect}. "\
57
- "The id is nil. This can be caused by connecting to a model "\
58
- "that is not saved, or that does not exist." unless id
59
- IncomingBroadcast.connect_to(channel.class.name, id)
60
- end
40
+ elsif channel.id
41
+ IncomingBroadcast.connect_to(channel.class.name, channel.id)
61
42
  else
62
- raise "Hyperstack.connect cannot connect to #{channel.inspect}.\n"\
63
- "Channels must be either a class, or a class name,\n"\
64
- "a string in the form 'ClassName-id',\n"\
65
- "an array in the form [class, id] or [class-name, id],\n"\
66
- "or an object that responds to the id method with a non-nil value"
43
+ raise "cannot connect to model before it has been saved"
67
44
  end
68
45
  end
69
46
  end
70
47
 
71
48
  def self.connect_session
72
- connect(['Hyperstack::Session', ClientDrivers.opts[:id].split('-').last])
49
+ connect(['Hyperloop::Session', ClientDrivers.opts[:id].split('-').last])
73
50
  end
74
51
 
75
52
  def self.action_cable_consumer
@@ -84,39 +61,36 @@ module Hyperstack
84
61
 
85
62
  def self.add_connection(channel_name, id = nil)
86
63
  channel_string = "#{channel_name}#{'-'+id.to_s if id}"
87
- return if open_channels.include? channel_string
88
64
  open_channels << channel_string
89
65
  channel_string
90
66
  end
91
67
 
92
68
  def self.connect_to(channel_name, id = nil)
93
69
  channel_string = add_connection(channel_name, id)
94
- return unless channel_string # already connected!
95
70
  if ClientDrivers.opts[:transport] == :pusher
96
71
  channel = "#{ClientDrivers.opts[:channel]}-#{channel_string}"
97
72
  %x{
98
73
  var channel = #{ClientDrivers.opts[:pusher_api]}.subscribe(#{channel.gsub('::', '==')});
99
74
  channel.bind('dispatch', #{ClientDrivers.opts[:dispatch]})
100
- channel.bind('pusher:subscription_succeeded', #{->(*) { ClientDrivers.get_queued_data("connect-to-transport", channel_string)}})
75
+ channel.bind('pusher:subscription_succeeded', #{lambda {ClientDrivers.get_queued_data("connect-to-transport", channel_string)}})
101
76
  }
102
- @pusher_dispatcher_registered = true
103
77
  elsif ClientDrivers.opts[:transport] == :action_cable
104
78
  channel = "#{ClientDrivers.opts[:channel]}-#{channel_string}"
105
- Hyperstack::HTTP.post(ClientDrivers.polling_path('action-cable-auth', channel), headers: { 'X-CSRF-Token' => ClientDrivers.opts[:form_authenticity_token] }).then do |response|
79
+ Hyperloop::HTTP.post(ClientDrivers.polling_path('action-cable-auth', channel), headers: { 'X-CSRF-Token' => ClientDrivers.opts[:form_authenticity_token] }).then do |response|
106
80
  %x{
107
81
  var fix_opal_0110 = 'return';
108
- #{Hyperstack.action_cable_consumer}.subscriptions.create(
82
+ #{Hyperloop.action_cable_consumer}.subscriptions.create(
109
83
  {
110
- channel: "Hyperstack::ActionCableChannel",
84
+ channel: "Hyperloop::ActionCableChannel",
111
85
  client_id: #{ClientDrivers.opts[:id]},
112
- hyperstack_channel: #{channel_string},
86
+ hyperloop_channel: #{channel_string},
113
87
  authorization: #{response.json[:authorization]},
114
88
  salt: #{response.json[:salt]}
115
89
  },
116
90
  {
117
91
  connected: function() {
118
92
  if (#{ClientDrivers.env == 'development'}) { console.log("ActionCable connected to: ", channel_string); }
119
- #{ClientDrivers.complete_connection(channel_string)}
93
+ #{ClientDrivers.get_queued_data("connect-to-transport", channel_string)}
120
94
  },
121
95
  received: function(data) {
122
96
  if (#{ClientDrivers.env == 'development'}) { console.log("ActionCable received: ", data); }
@@ -127,14 +101,14 @@ module Hyperstack
127
101
  }
128
102
  end
129
103
  else
130
- Hyperstack::HTTP.get(ClientDrivers.polling_path(:subscribe, channel_string))
104
+ Hyperloop::HTTP.get(ClientDrivers.polling_path(:subscribe, channel_string))
131
105
  end
132
106
  end
133
107
  end
134
108
  end
135
109
 
136
110
  class ClientDrivers
137
- include Hyperstack::Component::IsomorphicHelpers
111
+ include React::IsomorphicHelpers
138
112
 
139
113
  def self.sync_dispatch(data)
140
114
  # TODO old synchromesh double checked at this point to make sure that this client
@@ -142,7 +116,7 @@ module Hyperstack
142
116
  data[:operation].constantize.dispatch_from_server(data[:params])
143
117
  end
144
118
 
145
- # save the configuration info needed in window.HyperstackOpts
119
+ # save the configuration info needed in window.HyperloopOpts
146
120
 
147
121
  # we keep a list of all channels by session with connections in progress
148
122
  # for each broadcast we check the list, and add the message to a queue for that
@@ -151,51 +125,45 @@ module Hyperstack
151
125
  # will remove the session from the list.
152
126
 
153
127
  prerender_footer do |controller|
154
- unless Hyperstack.transport == :none
155
- if defined?(PusherFake)
156
- path = ::Rails.application.routes.routes.detect do |route|
157
- route.app == Hyperstack::Engine ||
158
- (route.app.respond_to?(:app) && route.app.app == Hyperstack::Engine)
159
- end.path.spec
160
- pusher_fake_js = PusherFake.javascript(
161
- auth: { headers: { 'X-CSRF-Token' => controller.send(:form_authenticity_token) } },
162
- authEndpoint: "#{path}/hyperstack-pusher-auth"
163
- )
164
- end
165
- controller.session.delete 'hyperstack-dummy-init' unless controller.session.id
166
- id = "#{SecureRandom.uuid}-#{controller.session.id}"
167
- auto_connections = Hyperstack::AutoConnect.channels(id, controller.acting_user) rescue []
128
+ next if Hyperloop.transport == :none
129
+ if defined?(PusherFake)
130
+ path = ::Rails.application.routes.routes.detect do |route|
131
+ route.app == Hyperloop::Engine ||
132
+ (route.app.respond_to?(:app) && route.app.app == Hyperloop::Engine)
133
+ end.path.spec
134
+ pusher_fake_js = PusherFake.javascript(
135
+ auth: { headers: { 'X-CSRF-Token' => controller.send(:form_authenticity_token) } },
136
+ authEndpoint: "#{path}/hyperloop-pusher-auth"
137
+ )
168
138
  end
139
+ controller.session.delete 'hyperloop-dummy-init' unless controller.session.id
140
+ id = "#{SecureRandom.uuid}-#{controller.session.id}"
141
+ auto_connections = Hyperloop::AutoConnect.channels(id, controller.acting_user)
169
142
  config_hash = {
170
- transport: Hyperstack.transport,
143
+ transport: Hyperloop.transport,
171
144
  id: id,
172
- acting_user_id: (controller.acting_user.respond_to?(:id) && controller.acting_user.id),
145
+ acting_user_id: (controller.acting_user && controller.acting_user.id),
173
146
  env: ::Rails.env,
174
- client_logging: Hyperstack.client_logging,
147
+ client_logging: Hyperloop.client_logging,
175
148
  pusher_fake_js: pusher_fake_js,
176
- key: Hyperstack.key,
177
- cluster: Hyperstack.cluster,
178
- encrypted: Hyperstack.encrypted,
179
- channel: Hyperstack.channel,
149
+ key: Hyperloop.key,
150
+ cluster: Hyperloop.cluster,
151
+ encrypted: Hyperloop.encrypted,
152
+ channel: Hyperloop.channel,
180
153
  form_authenticity_token: controller.send(:form_authenticity_token),
181
- seconds_between_poll: Hyperstack.seconds_between_poll,
154
+ seconds_between_poll: Hyperloop.seconds_between_poll,
182
155
  auto_connect: auto_connections
183
156
  }
184
157
  path = ::Rails.application.routes.routes.detect do |route|
185
158
  # not sure why the second check is needed. It happens in the test app
186
- route.app == Hyperstack::Engine or (route.app.respond_to?(:app) and route.app.app == Hyperstack::Engine)
187
- end
188
- if path
189
- path = path.path.spec
190
- "<script type='text/javascript'>\n"\
191
- "window.HyperstackEnginePath = '#{path}';\n"\
192
- "window.HyperstackOpts = #{config_hash.to_json}\n"\
193
- "</script>\n"
194
- else
195
- "<script type='text/javascript'>\n"\
196
- "window.HyperstackOpts = #{config_hash.to_json}\n"\
197
- "</script>\n"
159
+ route.app == Hyperloop::Engine or (route.app.respond_to?(:app) and route.app.app == Hyperloop::Engine)
198
160
  end
161
+ raise 'Hyperloop::Engine mount point not found. Check your config/routes.rb file' unless path
162
+ path = path.path.spec
163
+ "<script type='text/javascript'>\n"\
164
+ "window.HyperloopEnginePath = '#{path}';\n"\
165
+ "window.HyperloopOpts = #{config_hash.to_json}\n"\
166
+ "</script>\n"
199
167
  end if RUBY_ENGINE != 'opal'
200
168
 
201
169
  class << self
@@ -213,14 +181,8 @@ module Hyperstack
213
181
  f.when_on_server { ::Rails.env }
214
182
  end
215
183
 
216
- def self.complete_connection(channel, retries = 10)
217
- get_queued_data('connect-to-transport', channel).fail do
218
- after(0.25) { complete_connection(channel, retries - 1) } unless retries.zero?
219
- end
220
- end
221
-
222
184
  def self.get_queued_data(operation, channel = nil, opts = {})
223
- Hyperstack::HTTP.get(polling_path(operation, channel), opts).then do |response|
185
+ Hyperloop::HTTP.get(polling_path(operation, channel), opts).then do |response|
224
186
  response.json.each do |data|
225
187
  `console.log("simple_poller received: ", data)` if ClientDrivers.env == 'development'
226
188
  sync_dispatch(data[1])
@@ -232,11 +194,11 @@ module Hyperstack
232
194
 
233
195
  if @initialized
234
196
  # 1) skip initialization if already initialized
235
- if on_opal_client? && Hyperstack.action_cable_consumer
197
+ if on_opal_client? && Hyperloop.action_cable_consumer
236
198
  # 2) if running action_cable make sure connection is up after pinging the server_up
237
199
  # action cable closes the connection if files change on the server
238
- Hyperstack::HTTP.get("#{`window.HyperstackEnginePath`}/server_up") do
239
- `#{Hyperstack.action_cable_consumer}.connection.open()` if `#{Hyperstack.action_cable_consumer}.connection.disconnected`
200
+ Hyperloop::HTTP.get("#{`window.HyperloopEnginePath`}/server_up") do
201
+ `#{Hyperloop.action_cable_consumer}.connection.open()` if `#{Hyperloop.action_cable_consumer}.connection.disconnected`
240
202
  end
241
203
  end
242
204
  return
@@ -246,12 +208,9 @@ module Hyperstack
246
208
  @opts = {}
247
209
 
248
210
  if on_opal_client?
249
-
250
- @opts = Hash.new(`window.HyperstackOpts`)
251
-
252
- if opts[:transport] != :none && `typeof(window.HyperstackEnginePath) == 'undefined'`
253
- raise "No hyperstack mount point found!\nCheck your Rails routes.rb file";
254
- end
211
+
212
+ @opts = Hash.new(`window.HyperloopOpts`)
213
+
255
214
 
256
215
  if opts[:transport] == :pusher
257
216
 
@@ -271,18 +230,18 @@ module Hyperstack
271
230
  h = {
272
231
  encrypted: #{opts[:encrypted]},
273
232
  cluster: #{opts[:cluster]},
274
- authEndpoint: window.HyperstackEnginePath+'/hyperstack-pusher-auth',
233
+ authEndpoint: window.HyperloopEnginePath+'/hyperloop-pusher-auth',
275
234
  auth: {headers: {'X-CSRF-Token': #{opts[:form_authenticity_token]}}}
276
235
  };
277
236
  pusher_api = new Pusher(#{opts[:key]}, h)
278
237
  }
279
238
  opts[:pusher_api] = pusher_api
280
239
  end
281
- Hyperstack.connect(*opts[:auto_connect])
240
+ Hyperloop.connect(*opts[:auto_connect])
282
241
  elsif opts[:transport] == :action_cable
283
242
  opts[:action_cable_consumer] =
284
243
  `ActionCable.createConsumer.apply(ActionCable, #{[*opts[:action_cable_consumer_url]]})`
285
- Hyperstack.connect(*opts[:auto_connect])
244
+ Hyperloop.connect(*opts[:auto_connect])
286
245
  elsif opts[:transport] == :simple_poller
287
246
  opts[:auto_connect].each { |channel| IncomingBroadcast.add_connection(*channel) }
288
247
  every(opts[:seconds_between_poll]) do
@@ -293,7 +252,7 @@ module Hyperstack
293
252
  end
294
253
 
295
254
  def self.polling_path(to, id = nil)
296
- s = "#{`window.HyperstackEnginePath`}/hyperstack-#{to}/#{opts[:id]}"
255
+ s = "#{`window.HyperloopEnginePath`}/hyperloop-#{to}/#{opts[:id]}"
297
256
  s = "#{s}/#{id}" if id
298
257
  s
299
258
  end