isomorfeus-data 2.5.4 → 2.5.5

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: 198fe12b353be42d725a63ccd4495052c19a20a24e1f4223c3a2d4ac9c39fe4a
4
- data.tar.gz: bd01e302b472b1a1c847c5c49c5139edcb619faa48adfcdc3fd7e49996fcfaec
3
+ metadata.gz: 73175d7dc425cc54e235ee9719bacaaebe93b60753794949506cb044d05a5599
4
+ data.tar.gz: 1af87ebf47618289399a3cdf7539e533577f09ae0757cae9e5f7b873e3f05b59
5
5
  SHA512:
6
- metadata.gz: 410185c046e6c116eeca7e87fc84813f1961e23fc822f487714ab367f7e0f4f8e2e9090206138d0a0de43813420b8c9efa351aa099c8e2582e41f4ae35aa9216
7
- data.tar.gz: 7daa859033b8d5dd50d0dded8e3bcf3c2447ee825f0450358060ccee86ba32b55ea5a7cddad3e963d268db24c1545da9e7d56b1adc5e0ddca207d75c78d5ffc6
6
+ metadata.gz: 4fe59f656951f87f9382f4dfd2b86b00ba835644e69b729d51cc1eef6dbec9ca13a05e683d655cb085e536d1f13d0e738c42b15309e4ba681102e1d54bbca5ad
7
+ data.tar.gz: c2403b92cb3c88e1f38d05270afef98610694d8edd8cfca274735e4b456cfae2d2902db9512737dbd7316427dd7579d8f2275c691e64d6ac31e4c77affb725c4
@@ -3,6 +3,16 @@ module Isomorfeus
3
3
  module FieldSupport
4
4
  def self.included(base)
5
5
  base.instance_exec do
6
+ @@object_validation_proc = proc do |v|
7
+ fail = false
8
+ if v.is_a?(Array)
9
+ v.each { |e| fail = true unless e.nil? || e.is_a?(LucidObject::Mixin) }
10
+ elsif !v.nil? && !v.is_a?(LucidObject::Mixin)
11
+ fail = true
12
+ end
13
+ raise "must be nil, a LucidObject::Mixin or a Array of LucidObject::Mixin" if fail
14
+ end
15
+
6
16
  def field_types
7
17
  # determines how the item is stored in the index
8
18
  @field_types ||= {}
@@ -14,6 +24,7 @@ module Isomorfeus
14
24
  end
15
25
 
16
26
  def field_conditions
27
+ # conditions for validating the field data
17
28
  @field_conditions ||= {}
18
29
  end
19
30
 
@@ -43,7 +54,7 @@ module Isomorfeus
43
54
  alias embed attribute
44
55
 
45
56
  def object(name, options = {})
46
- default_options = { is_a: LucidObject::Mixin, allow_nil: true }
57
+ default_options = { validate_block: @@object_validation_proc }
47
58
  field(name, :object, default_options.merge(options))
48
59
  end
49
60
  alias reference object
@@ -189,7 +200,14 @@ module Isomorfeus
189
200
  path = @_store_path + [name]
190
201
  sid_or_array = Redux.fetch_by_path(*path)
191
202
  return nil if `(sid_or_array === null)`
192
- @_objects[name] = Isomorfeus.instance_from_sid(sid_or_array) if sid_or_array
203
+ if sid_or_array[0].is_a?(String)
204
+ @_objects[name] = Isomorfeus.instance_from_sid(sid_or_array)
205
+ elsif sid_or_array[0].is_a?(Array)
206
+ a = sid_or_array.map { |sid| Isomorfeus.instance_from_sid(sid) if sid }
207
+ a.compact!
208
+ @_objects[name] = a
209
+ end
210
+ @_objects[name]
193
211
  end
194
212
 
195
213
  def fields
@@ -202,7 +220,10 @@ module Isomorfeus
202
220
  def _get_selected_fields
203
221
  sel_fields = fields.dup
204
222
  self.class.field_types.each do |field, type|
205
- sel_fields[field] = sel_fields[field]&.sid if type == :object
223
+ if type == :object
224
+ v = sel_fields[field]
225
+ sel_fields[field] = v.is_a?(Array) ? v.map(&:sid) : v&.sid
226
+ end
206
227
  end
207
228
  sel_fields
208
229
  end
@@ -235,7 +256,8 @@ module Isomorfeus
235
256
  if options[:server_only]
236
257
  sel_fields.delete(field_s)
237
258
  elsif ft[field] == :object
238
- sel_fields[field_s] = sel_fields[field_s]&.sid
259
+ v = sel_fields[field_s]
260
+ sel_fields[field_s] = v.is_a?(Array) ? v.map(&:sid) : v&.sid
239
261
  end
240
262
  end
241
263
  sel_fields
@@ -20,6 +20,7 @@ module Isomorfeus
20
20
  end
21
21
 
22
22
  def object_from_ref(ref, already_loaded)
23
+ return nil if !ref || ref.empty?
23
24
  _, iso, type_class_name, key = ref.split('---')
24
25
  raise "not a valid object reference '#{ref}'" unless iso == "iso-object-reference"
25
26
  raise "invalid data class #{type_class_name}" unless Isomorfeus.valid_data_class_name?(type_class_name)
@@ -99,15 +100,30 @@ module Isomorfeus
99
100
  def unserialize_or_load(v, t, already_loaded)
100
101
  return unserialize(v) if t == :attribute
101
102
  if t == :object && v
102
- return nil if v.empty?
103
- return object_from_ref(v, already_loaded)
103
+ if v.is_a?(Array)
104
+ v = v.map { |e| object_from_ref(e, already_loaded) }
105
+ v.compact!
106
+ return v
107
+ else
108
+ return nil if v.empty?
109
+ return object_from_ref(v, already_loaded)
110
+ end
104
111
  end
105
112
  v
106
113
  end
107
114
 
108
115
  def serialize_or_save(v, t, already_saved)
109
116
  return serialize(v) if t == :attribute
110
- return create_or_save(v, already_saved) if t == :object && v
117
+ if t == :object && v
118
+ if v.is_a?(Array)
119
+ v = v.compact
120
+ v.map! { |e| create_or_save(e, already_saved) }
121
+ v.compact!
122
+ return v
123
+ else
124
+ return create_or_save(v, already_saved)
125
+ end
126
+ end
111
127
  v
112
128
  end
113
129
 
@@ -1,5 +1,5 @@
1
1
  module Isomorfeus
2
2
  module Data
3
- VERSION = '2.5.4'
3
+ VERSION = '2.5.5'
4
4
  end
5
5
  end
@@ -39,9 +39,16 @@ module LucidObject
39
39
  if type == :object
40
40
  v = f[field]
41
41
  if v
42
- data_hash.deep_merge!(v.to_transport)
43
- if v.respond_to?(:included_items_to_transport)
44
- data_hash.deep_merge!(v.included_items_to_transport)
42
+ if v.is_a?(LucidObject::Mixin)
43
+ data_hash.deep_merge!(v.to_transport)
44
+ data_hash.deep_merge!(v.included_items_to_transport) if v.respond_to?(:included_items_to_transport)
45
+ elsif v.is_a?(Array)
46
+ v.each do |e|
47
+ if e
48
+ data_hash.deep_merge!(e.to_transport)
49
+ data_hash.deep_merge!(e.included_items_to_transport) if e.respond_to?(:included_items_to_transport)
50
+ end
51
+ end
45
52
  end
46
53
  end
47
54
  end
@@ -99,6 +106,14 @@ module LucidObject
99
106
  Isomorfeus.add_valid_data_class(base) unless base == LucidObject::Base
100
107
 
101
108
  base.instance_exec do
109
+ def _instance_from_transport_sid(sid, included_items_data, _already_loaded)
110
+ o_class_name = sid[0]
111
+ raise "invalid data class #{o_class_name}" unless Isomorfeus.valid_data_class_name?(o_class_name)
112
+ o_class = Isomorfeus.cached_data_class(o_class_name)
113
+ o_data = { o_class_name => { sid[1] => included_items_data[o_class_name][sid[1]] }}
114
+ o_class.instance_from_transport(o_data, included_items_data, _already_loaded)
115
+ end
116
+
102
117
  def instance_from_transport(instance_data, included_items_data, _already_loaded = {})
103
118
  key = instance_data[self.name].keys.first
104
119
  ref_s = gen_ref_s(key)
@@ -110,16 +125,15 @@ module LucidObject
110
125
  if fields
111
126
  field_types.each do |field, type|
112
127
  if type == :object
113
- sid = fields[field]
114
- if sid
115
- o_class_name = sid[0]
116
- raise "invalid data class #{type_class_name}" unless Isomorfeus.valid_data_class_name?(o_class_name)
117
- o_class = Isomorfeus.cached_data_class(o_class_name)
118
- o_data = { o_class_name => { sid[1] => included_items_data[o_class_name][sid[1]] }}
119
- if included_items_data && !included_items_data[self.name]&.key?(key)
120
- included_items_data.deep_merge!(instance_data)
128
+ sid_or_array = fields[field]
129
+ if sid_or_array&.any?
130
+ if sid_or_array[0].is_a? String
131
+ fields[field] = _instance_from_transport_sid(sid_or_array, included_items_data, _already_loaded)
132
+ elsif sid_or_array[0].is_a? Array
133
+ v = sid_or_array.map { |e_sid| _instance_from_transport_sid(e_sid, included_items_data, _already_loaded) }
134
+ v.compact!
135
+ fields[field] = v
121
136
  end
122
- fields[field] = o_class.instance_from_transport(o_data, included_items_data, _already_loaded)
123
137
  end
124
138
  end
125
139
  end
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: 2.5.4
4
+ version: 2.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Biedermann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-31 00:00:00.000000000 Z
11
+ date: 2022-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -100,28 +100,28 @@ dependencies:
100
100
  requirements:
101
101
  - - '='
102
102
  - !ruby/object:Gem::Version
103
- version: 2.5.4
103
+ version: 2.5.5
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: 2.5.4
110
+ version: 2.5.5
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: isomorfeus-policy
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - '='
116
116
  - !ruby/object:Gem::Version
117
- version: 2.5.4
117
+ version: 2.5.5
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: 2.5.4
124
+ version: 2.5.5
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: isomorfeus-preact
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -156,28 +156,28 @@ dependencies:
156
156
  requirements:
157
157
  - - '='
158
158
  - !ruby/object:Gem::Version
159
- version: 2.5.4
159
+ version: 2.5.5
160
160
  type: :runtime
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - '='
165
165
  - !ruby/object:Gem::Version
166
- version: 2.5.4
166
+ version: 2.5.5
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: isomorfeus
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
171
  - - '='
172
172
  - !ruby/object:Gem::Version
173
- version: 2.5.4
173
+ version: 2.5.5
174
174
  type: :development
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
178
  - - '='
179
179
  - !ruby/object:Gem::Version
180
- version: 2.5.4
180
+ version: 2.5.5
181
181
  - !ruby/object:Gem::Dependency
182
182
  name: rake
183
183
  requirement: !ruby/object:Gem::Requirement