isomorfeus-data 1.0.0.zeta14 → 1.0.0.zeta15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 93156d6e98ea25e9b5710ccfa92e5efadfa0e1f0f5e9e1fa2d9a1aa239a25693
4
- data.tar.gz: ee280984d99c9a45734a29f99d1108f1da5b37083f6f861573ba3c1b4c40e0e2
3
+ metadata.gz: 5892f945be6dc4dbca02003669dd3c2a1b21d91a615758100ef0be3d721eacfc
4
+ data.tar.gz: 657b5dc1d817833c68f97fff026e69e3f85348400bce5bed565a9b8b5a950189
5
5
  SHA512:
6
- metadata.gz: 938d8e16c20f5cc9600397d30c9c95c2efaa2774391eda20131c94a0347ec5a724208f1cd2c83fe7d890ea16223c8d68ef9994cf14d495f1db90c00a3bf6627e
7
- data.tar.gz: 58b5ad7dbe2a9ff0d73b4c86ec93ab62d8f4804a78de8ee22184693aa2cc7b9e6cac55ddb70038486de288f31e10949908557319507d9aa07de2c3082c36a69f
6
+ metadata.gz: bd5e0a7b0d9e63288238b916225669ed6ae17357145afaa36990d0fc3e908ecf1088f179b93c56bbe1d68ff76ec70164b4a38bab7235ba17bb1b018b6689196a
7
+ data.tar.gz: 54b1606d43f61b0ecc0d24c0652a89549225f43dff50cd73b8da78f91fb474f85d77b0ba53ce7775953ad25ef5df0af1384f6839ad5e1358c9055ad8610d4a99
data/README.md CHANGED
@@ -22,6 +22,7 @@ Data must then be shaped (usually in to a Hash or Array) to fit the Isomorfeus D
22
22
 
23
23
  - [Core Concepts](https://github.com/isomorfeus/isomorfeus-project/blob/master/ruby/isomorfeus-data/docs/concepts.md)
24
24
  - [Common API](https://github.com/isomorfeus/isomorfeus-project/blob/master/ruby/isomorfeus-data/docs/common_api.md)
25
+ - [Data Policy](https://github.com/isomorfeus/isomorfeus-project/blob/master/ruby/isomorfeus-data/docs/data_policy.md)
25
26
 
26
27
  ### Available Classes
27
28
 
@@ -102,26 +102,30 @@ module Isomorfeus
102
102
  }
103
103
  end
104
104
 
105
- def _get_attributes
105
+ def attributes
106
106
  raw_attributes = Redux.fetch_by_path(*@_store_path)
107
107
  hash = Hash.new(raw_attributes)
108
108
  hash.merge!(@_changed_attributes) if @_changed_attributes
109
109
  hash
110
110
  end
111
111
 
112
+ def native_attributes
113
+ Redux.fetch_by_path(*@_store_path)
114
+ end
115
+
112
116
  def _get_selected_attributes
113
- attributes = _get_attributes.dup
117
+ sel_attributes = attributes.dup
114
118
  if @_selected_attributes && !@_selected_attributes.empty?
115
- attributes.each_key do |attr|
119
+ sel_attributes.each_key do |attr|
116
120
  unless @_selected_attributes.include?(attr) || @_selected_attributes.include?(attr)
117
- attributes.delete(attr)
121
+ sel_attributes.delete(attr)
118
122
  end
119
123
  end
120
124
  end
121
125
  if @_excluded_attributes && !@_excluded_attributes.empty?
122
- @_excluded_attributes.each { |attr| attributes.delete(attr) }
126
+ @_excluded_attributes.each { |attr| sel_attributes.delete(attr) }
123
127
  end
124
- attributes
128
+ sel_attributes
125
129
  end
126
130
  else
127
131
  base.instance_exec do
@@ -140,26 +144,30 @@ module Isomorfeus
140
144
  end
141
145
  end
142
146
 
143
- def _get_attributes
147
+ def attributes
148
+ @_raw_attributes
149
+ end
150
+
151
+ def native_attributes
144
152
  @_raw_attributes
145
153
  end
146
154
 
147
155
  def _get_selected_attributes
148
- attributes = _get_attributes.transform_keys(&:to_s)
156
+ sel_attributes = attributes.transform_keys(&:to_s)
149
157
  self.class.attribute_conditions.each do |attr, options|
150
- attributes.delete(attr.to_s) if options[:server_only]
158
+ sel_attributes.delete(attr.to_s) if options[:server_only]
151
159
  end
152
160
  if @_selected_attributes && !@_selected_attributes.empty?
153
- attributes.each_key do |attr|
161
+ sel_attributes.each_key do |attr|
154
162
  unless @_selected_attributes.include?(attr.to_sym) || @_selected_attributes.include?(attr)
155
- attributes.delete(attr)
163
+ sel_attributes.delete(attr)
156
164
  end
157
165
  end
158
166
  end
159
167
  if @_excluded_attributes && !@_excluded_attributes.empty?
160
- @_excluded_attributes.each { |attr| attributes.delete(attr.to_s) }
168
+ @_excluded_attributes.each { |attr| sel_attributes.delete(attr.to_s) }
161
169
  end
162
- attributes
170
+ sel_attributes
163
171
  end
164
172
  end
165
173
  end
@@ -55,43 +55,47 @@ module Isomorfeus
55
55
  end
56
56
 
57
57
  def prepare_arango_database
58
- #arango_options = if Isomorfeus.production? then Isomorfeus.arango_production
59
- # elsif Isomorfeus.development? then Isomorfeus.arango_development
60
- # elsif Isomorfeus.test? then Isomorfeus.arango_test
61
- # end
62
- #arango_options = {}.merge(arango_options)
63
- #database = arango_options.delete(:database)
64
- #Arango.connect_to(**arango_options)
65
- #db = nil
66
- #begin
67
- # opened_db = Arango.current_server.get_database(database)
68
- # db = opened_db.name
69
- #rescue Exception => e
70
- # db = nil
71
- # unless e.message.include?('database not found')
72
- # raise "Can't check if database '#{database}' exists."
73
- # end
74
- #end
75
- #unless db
76
- # begin
77
- # Arango.current_server.create_database(database)
78
- # rescue Exception => e
79
- # raise "Can't create database '#{database}' (#{e.message}).\nPlease make sure database '#{database}' exists."
80
- # end
81
- # begin
82
- # Arango.current_server.get_database(database)
83
- # rescue Exception => e
84
- # raise "Can't connect to database '#{database}' (#{e.message})."
85
- # end
86
- #end
87
- #
88
- #Arango.current_server.install_opal_module(database)
89
- #unless Arango.current_database.collection_exist?('IsomorfeusSessions')
90
- # Arango.current_database.create_collection('IsomorfeusSessions')
91
- #end
92
- #unless Arango.current_database.collection_exist?('IsomorfeusObjectStore')
93
- # Arango.current_database.create_collection('IsomorfeusObjectStore')
94
- #end
58
+ unless arango_configured?
59
+ STDOUT.puts "ArangoDB not configured, not preparing things, not using ArangoDB"
60
+ return
61
+ end
62
+ arango_options = if Isomorfeus.production? then Isomorfeus.arango_production
63
+ elsif Isomorfeus.development? then Isomorfeus.arango_development
64
+ elsif Isomorfeus.test? then Isomorfeus.arango_test
65
+ end
66
+ arango_options = {}.merge(arango_options)
67
+ database = arango_options.delete(:database)
68
+ Arango.connect_to(**arango_options)
69
+ db = nil
70
+ begin
71
+ opened_db = Arango.current_server.get_database(database)
72
+ db = opened_db.name
73
+ rescue Exception => e
74
+ db = nil
75
+ unless e.message.include?('database not found')
76
+ Isomorfeus.raise_error(message: "Can't check if database '#{database}' exists.")
77
+ end
78
+ end
79
+ unless db
80
+ begin
81
+ Arango.current_server.create_database(database)
82
+ rescue Exception => e
83
+ Isomorfeus.raise_error(message: "Can't create database '#{database}' (#{e.message}).\nPlease make sure database '#{database}' exists.")
84
+ end
85
+ begin
86
+ Arango.current_server.get_database(database)
87
+ rescue Exception => e
88
+ Isomorfeus.raise_error(message: "Can't connect to database '#{database}' (#{e.message}).")
89
+ end
90
+ end
91
+
92
+ Arango.current_server.install_opal_module(database)
93
+ unless Arango.current_database.collection_exist?('IsomorfeusSessions')
94
+ Arango.current_database.create_collection('IsomorfeusSessions')
95
+ end
96
+ unless Arango.current_database.collection_exist?('IsomorfeusObjectStore')
97
+ Arango.current_database.create_collection('IsomorfeusObjectStore')
98
+ end
95
99
  end
96
100
 
97
101
  def arango_configured?
@@ -2,16 +2,6 @@ module Isomorfeus
2
2
  module Data
3
3
  module GenericClassApi
4
4
  if RUBY_ENGINE == 'opal'
5
- def create(key:, **things)
6
- instance = new(key: key, **things)
7
- instance.promise_save
8
- instance
9
- end
10
-
11
- def promise_create(key:, **things)
12
- new(key: key, **things).promise_save
13
- end
14
-
15
5
  def destroy(key:)
16
6
  promise_destroy(key: key)
17
7
  true
@@ -57,34 +47,12 @@ module Isomorfeus
57
47
  end
58
48
  end
59
49
 
60
- def save(instance:)
61
- instance.promise_save
62
- instance
63
- end
64
-
65
- def promise_save(instance:)
66
- instance.promise_save
67
- end
68
-
69
50
  # execute
51
+ def execute_create(_); end
70
52
  def execute_destroy(_); end
71
53
  def execute_load(_); end
72
54
  def execute_save(_); end
73
55
  else
74
- def promise_create(key:, **things)
75
- instance = self.create(key: key, **things)
76
- result_promise = Promise.new
77
- result_promise.resolve(instance)
78
- result_promise
79
- end
80
-
81
- def promise_destroy(key:)
82
- result = self.destroy(key: key)
83
- result_promise = Promise.new
84
- result_promise.resolve(result)
85
- result_promise
86
- end
87
-
88
56
  def destroy(key:)
89
57
  !!instance_exec(key: key, &@_destroy_block)
90
58
  end
@@ -104,17 +72,11 @@ module Isomorfeus
104
72
  data
105
73
  end
106
74
 
107
- def save(instance:)
108
- previous_key = instance.key
109
- data = instance_exec(instance: instance, &@_save_block)
110
- return nil unless data
111
- Isomorfeus.raise_error(message: "#{self.to_s}: execute_save must return a instance of #{self.to_s} or nil. Returned was: #{data.class}.") if data.class != self
112
- data.instance_variable_set(:@previous_key, previous_key) if data.key != previous_key
113
- data._unchange!
114
- data
75
+ # execute
76
+ def execute_create(&block)
77
+ @_create_block = block
115
78
  end
116
79
 
117
- # execute
118
80
  def execute_destroy(&block)
119
81
  @_destroy_block = block
120
82
  end
@@ -128,6 +90,22 @@ module Isomorfeus
128
90
  end
129
91
  end
130
92
 
93
+ def create(key:, **things)
94
+ new(key: key, **things).create
95
+ end
96
+
97
+ def promise_create(key:, **things)
98
+ new(key: key, **things).promise_create
99
+ end
100
+
101
+ def save(instance:)
102
+ instance.save
103
+ end
104
+
105
+ def promise_save(instance:)
106
+ instance.promise_save
107
+ end
108
+
131
109
  def current_user
132
110
  Isomorfeus.current_user
133
111
  end
@@ -22,6 +22,37 @@ module Isomorfeus
22
22
  Redux.fetch_by_path(*@_store_path) ? true : false
23
23
  end
24
24
 
25
+ def create
26
+ promise_create
27
+ self
28
+ end
29
+
30
+ def promise_create
31
+ data_hash = { instance: to_transport }
32
+ data_hash.deep_merge!(included_items: included_items_to_transport) if respond_to?(:included_items_to_transport)
33
+ class_name = self.class.name
34
+ Isomorfeus::Transport.promise_send_path( 'Isomorfeus::Data::Handler::Generic', class_name, :create, data_hash).then do |agent|
35
+ if agent.processed
36
+ agent.result
37
+ else
38
+ agent.processed = true
39
+ if agent.response.key?(:error)
40
+ `console.error(#{agent.response[:error].to_n})`
41
+ Isomorfeus.raise_error(message: agent.response[:error])
42
+ end
43
+ data = agent.full_response[:data]
44
+ if data.key?(class_name) && data[class_name].key?(@key) && data[class_name][@key].key?('new_key')
45
+ @key = data[class_name][@key]['new_key']
46
+ @revision = data[class_name][@key]['revision'] if data[class_name][@key].key?('revision')
47
+ _update_paths
48
+ end
49
+ _load_from_store!
50
+ Isomorfeus.store.dispatch(type: 'DATA_LOAD', data: data)
51
+ agent.result = self
52
+ end
53
+ end
54
+ end
55
+
25
56
  def destroy
26
57
  promise_destroy
27
58
  nil
@@ -40,12 +71,6 @@ module Isomorfeus
40
71
  self.class.promise_load(@key, self)
41
72
  end
42
73
 
43
- def save
44
- promise_save
45
- self
46
- end
47
- alias create save
48
-
49
74
  def promise_save
50
75
  data_hash = { instance: to_transport }
51
76
  data_hash.deep_merge!(included_items: included_items_to_transport) if respond_to?(:included_items_to_transport)
@@ -71,7 +96,6 @@ module Isomorfeus
71
96
  end
72
97
  end
73
98
  end
74
- alias promise_create promise_save
75
99
 
76
100
  # TODO update -> only send partial change
77
101
  # included_changed_items
@@ -80,8 +104,28 @@ module Isomorfeus
80
104
  true
81
105
  end
82
106
 
107
+ def create
108
+ previous_key = self.key
109
+ instance = instance_exec(&self.class.instance_variable_get(:@_create_block))
110
+ return nil unless instance
111
+ Isomorfeus.raise_error(message: "#{self.to_s}: execute_create must return self or nil. Returned was: #{instance.class}.") if instance != self
112
+ instance_variable_set(:@previous_key, previous_key) if key != previous_key
113
+ _unchange!
114
+ self
115
+ end
116
+
117
+ def promise_create
118
+ promise = Promise.new
119
+ promise.resolve(create)
120
+ end
121
+
83
122
  def save
84
- self.class.save(instance: self)
123
+ previous_key = self.key
124
+ instance = instance_exec(&self.class.instance_variable_get(:@_save_block))
125
+ return nil unless instance
126
+ Isomorfeus.raise_error(message: "#{self.to_s}: execute_save must return self or nil. Returned was: #{instance.class}.") if instance != self
127
+ instance_variable_set(:@previous_key, previous_key) if key != previous_key
128
+ _unchange!
85
129
  self
86
130
  end
87
131
 
@@ -24,6 +24,7 @@ module Isomorfeus
24
24
  case action
25
25
  when 'load' then process_load(response_agent, type_class, type_class_name)
26
26
  when 'execute' then process_execute(response_agent, type_class, type_class_name)
27
+ when 'create' then process_create(response_agent, type_class, type_class_name)
27
28
  when 'save' then process_save(response_agent, type_class, type_class_name)
28
29
  when 'destroy' then process_destroy(response_agent, type_class, type_class_name)
29
30
  else response_agent.error = { error: { action => 'No such thing!' }}
@@ -38,6 +39,27 @@ module Isomorfeus
38
39
  response_agent.error = { error: "Isomorfeus::Data::Handler::Generic: #{e.message}\n#{e.backtrace.join("\n")}" }
39
40
  end
40
41
 
42
+ def process_create(response_agent, type_class, type_class_name)
43
+ # 'Isomorfeus::Data::Handler::Generic', self.name, :create, data_hash
44
+ data = response_agent.request[type_class_name]['save']
45
+ instance_data = data['instance']
46
+ included_items_data = data.key?('included_items') ? data['included_items'] : nil
47
+ if Isomorfeus.current_user.authorized?(type_class, :create, data)
48
+ instance = type_class.instance_from_transport(instance_data, included_items_data)
49
+ created_type = instance.create
50
+ if created_type
51
+ response_agent.outer_result = {} unless response_agent.outer_result
52
+ response_agent.outer_result.deep_merge!(data: created_type.to_transport)
53
+ if created_type.respond_to?(:included_items_to_transport)
54
+ response_agent.outer_result.deep_merge!(data: created_type.included_items_to_transport)
55
+ end
56
+ response_agent.agent_result = { success: 'ok' }
57
+ else response_agent.error = { error: { type_class_name => 'Create returned nothing!' }}
58
+ end
59
+ else response_agent.error = { error: 'Access denied!' }
60
+ end
61
+ end
62
+
41
63
  def process_load(response_agent, type_class, type_class_name)
42
64
  # 'Isomorfeus::Data::Handler::Generic', self.name, :load, key: key
43
65
  props = response_agent.request[type_class_name]['load']
@@ -59,11 +81,9 @@ module Isomorfeus
59
81
 
60
82
  def process_execute(response_agent, type_class, type_class_name)
61
83
  # 'Isomorfeus::Data::Handler::Generic', self.name, :execute, props_json
62
- props_json = response_agent.request[type_class_name]['execute']
63
- props = Oj.load(props_json, mode: :strict)
84
+ props = response_agent.request[type_class_name]['execute']
64
85
  props.transform_keys!(&:to_sym)
65
- props[:props].transform_keys!(&:to_sym)
66
- if Isomorfeus.current_user.authorized?(type_class, :execute, props[:props])
86
+ if Isomorfeus.current_user.authorized?(type_class, :execute, props)
67
87
  queried_type = type_class.execute(**props)
68
88
  if queried_type
69
89
  response_agent.outer_result = {} unless response_agent.outer_result
@@ -85,7 +105,7 @@ module Isomorfeus
85
105
  included_items_data = data.key?('included_items') ? data['included_items'] : nil
86
106
  if Isomorfeus.current_user.authorized?(type_class, :save, data)
87
107
  instance = type_class.instance_from_transport(instance_data, included_items_data)
88
- saved_type = type_class.save(instance: instance)
108
+ saved_type = instance.save
89
109
  if saved_type
90
110
  response_agent.outer_result = {} unless response_agent.outer_result
91
111
  response_agent.outer_result.deep_merge!(data: saved_type.to_transport)
@@ -1,5 +1,5 @@
1
1
  module Isomorfeus
2
2
  module Data
3
- VERSION = '1.0.0.zeta14'
3
+ VERSION = '1.0.0.zeta15'
4
4
  end
5
5
  end
@@ -15,6 +15,7 @@ else
15
15
  require 'oj'
16
16
  require 'active_support'
17
17
  require 'active_support/core_ext/hash'
18
+ require 'arango-driver'
18
19
 
19
20
  require 'isomorfeus_data/lucid_data/query_result'
20
21
  require 'isomorfeus_data/lucid_data/array/mixin'
@@ -119,7 +119,7 @@ module LucidData
119
119
  end
120
120
 
121
121
  def each(&block)
122
- _get_attributes.each(&block)
122
+ attributes.each(&block)
123
123
  end
124
124
 
125
125
  def [](name)
@@ -402,7 +402,7 @@ module LucidData
402
402
  hash.each do |name, value|
403
403
  namsy = name.to_sym
404
404
  nodes_edges[namsy] = []
405
- hash[name].each do |sid|
405
+ value.each do |sid|
406
406
  node_class_name = sid[0]
407
407
  node_key = sid[1]
408
408
  Isomorfeus.raise_error(message: "#{self.name}: #{node_class_name}: Not a valid LucidData class!") unless Isomorfeus.valid_data_class_name?(node_class_name)
@@ -411,7 +411,7 @@ module LucidData
411
411
  Isomorfeus.raise_error(message: "#{self.name}: #{node_class_name}: Cannot get class!") unless node_class
412
412
  node = node_class.instance_from_transport({ node_class_name => { node_key => included_items_data[node_class_name][node_key] }}, included_items_data)
413
413
  Isomorfeus.raise_error(message: "#{self.name}: #{node_class_name} with key #{node_key} could not be extracted from transport data!") unless node
414
- nodes_edges[namsy] << node
414
+ nodes_edges[hash_index][namsy] << node
415
415
  end
416
416
  end
417
417
  end
@@ -114,7 +114,7 @@ module LucidData
114
114
  result
115
115
  end
116
116
 
117
- def _get_attributes
117
+ def attributes
118
118
  raw_attributes = Redux.fetch_by_path(*@_store_path)
119
119
  hash = ::Hash.new(raw_attributes)
120
120
  hash.merge!(@_changed_attributes) if @_changed_attributes
@@ -135,7 +135,7 @@ module LucidData
135
135
  end
136
136
 
137
137
  def each(&block)
138
- _get_attributes.each(&block)
138
+ attributes.each(&block)
139
139
  end
140
140
 
141
141
  def [](name)
@@ -152,7 +152,7 @@ module LucidData
152
152
  end
153
153
 
154
154
  def compact!
155
- result = _get_attributes.compact!
155
+ result = attributes.compact!
156
156
  return nil if result.nil?
157
157
  @_changed_attributes = result
158
158
  changed!
@@ -160,7 +160,7 @@ module LucidData
160
160
  end
161
161
 
162
162
  def delete(name)
163
- hash = _get_attributes
163
+ hash = attributes
164
164
  result = hash.delete(name)
165
165
  @_changed_attributes = hash
166
166
  changed!
@@ -168,7 +168,7 @@ module LucidData
168
168
  end
169
169
 
170
170
  def delete_if(&block)
171
- hash = _get_attributes
171
+ hash = attributes
172
172
  result = hash.delete_if(&block)
173
173
  @_changed_attributes = hash
174
174
  changed!
@@ -187,7 +187,7 @@ module LucidData
187
187
  return @_default unless @_default_proc
188
188
  @_default_proc.call(self, method_name)
189
189
  else
190
- hash = _get_attributes
190
+ hash = attributes
191
191
  hash.send(name, *args, &block)
192
192
  end
193
193
  end
@@ -198,7 +198,7 @@ module LucidData
198
198
  alias has_key? key?
199
199
 
200
200
  def keep_if(&block)
201
- raw_hash = _get_attributes
201
+ raw_hash = attributes
202
202
  raw_hash.keep_if(&block)
203
203
  @_changed_attributes = raw_hash
204
204
  changed!
@@ -206,13 +206,13 @@ module LucidData
206
206
  end
207
207
 
208
208
  def merge!(*args)
209
- @_changed_attributes = _get_attributes.merge!(*args)
209
+ @_changed_attributes = attributes.merge!(*args)
210
210
  changed!
211
211
  self
212
212
  end
213
213
 
214
214
  def reject!(&block)
215
- hash = _get_attributes
215
+ hash = attributes
216
216
  result = hash.reject!(&block)
217
217
  return nil if result.nil?
218
218
  @_changed_attributes = hash
@@ -221,7 +221,7 @@ module LucidData
221
221
  end
222
222
 
223
223
  def select!(&block)
224
- hash = _get_attributes
224
+ hash = attributes
225
225
  result = hash.select!(&block)
226
226
  return nil if result.nil?
227
227
  @_changed_attributes = hash
@@ -231,7 +231,7 @@ module LucidData
231
231
  alias filter! select!
232
232
 
233
233
  def shift
234
- hash = _get_attributes
234
+ hash = attributes
235
235
  result = hash.shift
236
236
  @_changed_attributes = hash
237
237
  changed!
@@ -246,23 +246,23 @@ module LucidData
246
246
  end
247
247
 
248
248
  def to_h
249
- _get_attributes.dup
249
+ attributes.dup
250
250
  end
251
251
 
252
252
  def transform_keys!(&block)
253
- @_changed_attributes = _get_attributes.transform_keys!(&block)
253
+ @_changed_attributes = attributes.transform_keys!(&block)
254
254
  changed!
255
255
  self
256
256
  end
257
257
 
258
258
  def transform_values!(&block)
259
- @_changed_attributes = _get_attributes.transform_values!(&block)
259
+ @_changed_attributes = attributes.transform_values!(&block)
260
260
  changed!
261
261
  self
262
262
  end
263
263
 
264
264
  def update(*args)
265
- @_changed_attributes = _get_attributes.update(*args)
265
+ @_changed_attributes = attributes.update(*args)
266
266
  changed!
267
267
  self
268
268
  end
@@ -90,7 +90,7 @@ module LucidData
90
90
  end
91
91
 
92
92
  def each(&block)
93
- _get_attributes.each(&block)
93
+ attributes.each(&block)
94
94
  end
95
95
 
96
96
  def [](name)
@@ -6,21 +6,21 @@ module LucidData
6
6
 
7
7
  if RUBY_ENGINE == 'opal'
8
8
  base.instance_exec do
9
- def execute(props:)
10
- query_result_instance = LucidData::QueryResult.new
11
- promise_execute(props: props, query_result_instance: query_result_instance) unless query_result_instance.loaded?
12
- query_result_instance
9
+ def execute(**props)
10
+ props[:query_result_instance] = LucidData::QueryResult.new
11
+ promise_execute(props) unless props[:query_result_instance].loaded?
12
+ props[:query_result_instance]
13
13
  end
14
14
 
15
- def promise_execute(props:, query_result_instance: nil)
15
+ def promise_execute(**props)
16
+ query_result_instance = props.delete(:query_result_instance)
16
17
  query_result_instance = LucidData::QueryResult.new unless query_result_instance
17
18
  props.each_key do |prop_name|
18
19
  Isomorfeus.raise_error(message: "#{self.to_s} No such query prop declared: '#{prop_name}'!") unless declared_props.key?(prop_name)
19
20
  end
20
- validate_props(props)
21
- data_props = { props: props, query_result_instance_key: query_result_instance.key }
22
- props_json = data_props.to_json
23
- Isomorfeus::Transport.promise_send_path( 'Isomorfeus::Data::Handler::Generic', self.name, :execute, props_json).then do |agent|
21
+ props = validated_props(props)
22
+ props[:query_result_instance_key] = query_result_instance.key
23
+ Isomorfeus::Transport.promise_send_path( 'Isomorfeus::Data::Handler::Generic', self.name, :execute, props).then do |agent|
24
24
  if agent.processed
25
25
  agent.result
26
26
  else
@@ -44,34 +44,30 @@ module LucidData
44
44
  end
45
45
 
46
46
  base.instance_exec do
47
- def promise_execute(props:)
48
- instance = self.execute(props: props)
47
+ def promise_execute(**props)
48
+ instance = self.execute(**props)
49
49
  result_promise = Promise.new
50
50
  result_promise.resolve(instance)
51
51
  result_promise
52
52
  end
53
53
 
54
- def execute(props:, query_result_instance_key: nil)
55
- props.each_key do |prop_name|
56
- Isomorfeus.raise_error(message: "#{self.to_s} No such query prop declared: '#{prop_name}'!") unless declared_props.key?(prop_name)
57
- end
58
- validate_props(props)
54
+ def execute(**props)
55
+ query_result_instance_key = props.delete(:query_result_instance_key)
59
56
  query_result = LucidData::QueryResult.new(key: query_result_instance_key)
60
- query_result.result_set = instance_exec(props: Isomorfeus::PropsProxy.new(props), &@_query_block)
57
+ query_result.result_set = self.new(**props).instance_exec(&@_query_block)
61
58
  query_result
62
59
  end
63
60
 
64
61
  def execute_query(&block)
65
62
  @_query_block = block
66
63
  end
64
+ end
67
65
 
68
- def current_user
69
- Isomorfeus.current_user
70
- end
66
+ attr_reader :props
71
67
 
72
- def pub_sub_client
73
- Isomorfeus.pub_sub_client
74
- end
68
+ def initialize(**props_hash)
69
+ props_hash = self.class.validated_props(props_hash)
70
+ @props = LucidProps.new(props_hash)
75
71
  end
76
72
 
77
73
  def current_user
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isomorfeus-data
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.zeta14
4
+ version: 1.0.0.zeta15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Biedermann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-28 00:00:00.000000000 Z
11
+ date: 2020-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: 16.12.14
89
+ version: 16.12.17
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.14
96
+ version: 16.12.17
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: isomorfeus-redux
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -114,28 +114,28 @@ dependencies:
114
114
  requirements:
115
115
  - - '='
116
116
  - !ruby/object:Gem::Version
117
- version: 1.0.0.zeta14
117
+ version: 1.0.0.zeta15
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - '='
123
123
  - !ruby/object:Gem::Version
124
- version: 1.0.0.zeta14
124
+ version: 1.0.0.zeta15
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: isomorfeus
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - '='
130
130
  - !ruby/object:Gem::Version
131
- version: 1.0.0.zeta14
131
+ version: 1.0.0.zeta15
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.zeta14
138
+ version: 1.0.0.zeta15
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: opal-webpack-loader
141
141
  requirement: !ruby/object:Gem::Requirement