deep_unrest 0.1.65 → 0.1.70
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/deep_unrest/application_controller.rb +1 -0
- data/config/routes.rb +1 -0
- data/lib/deep_unrest.rb +21 -11
- data/lib/deep_unrest/read.rb +12 -2
- data/lib/deep_unrest/version.rb +1 -1
- data/lib/deep_unrest/write.rb +2 -3
- metadata +18 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ef68924e90a33009700f08b985e9855d1d66710be4d11f059c075bb921cbe5c
|
4
|
+
data.tar.gz: 657a8ec04cdc0b0809a2210333df22915ab4611cdbb01bd9479c82766950db0f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d3ff2ef8aba1c1b7d7fbf9f804bc39a67f75b0c4db85afdc2dec1c5fc05121d9e3724b57b0deffabe1ca0f94626b6bb591d17a51bdbfcc3d063cc49739d28c3
|
7
|
+
data.tar.gz: c5ae82beb75ac2772f162710bf978f0ca9960a83ef428c2d67dea685d34427e7ddaa95f9c265fc1e579784e86f0a59dc2083c6e8ea0248e780e9a94f50607b76
|
@@ -51,6 +51,7 @@ module DeepUnrest
|
|
51
51
|
def write
|
52
52
|
repaired_params = repair_nested_params(params[:data])
|
53
53
|
data = repaired_params[:data]
|
54
|
+
data = ActionController::Parameters.new({}) if data&.blank?
|
54
55
|
context = repaired_params[:context] || {}
|
55
56
|
context[:uuid] = request.uuid
|
56
57
|
context[:current_user] = current_user
|
data/config/routes.rb
CHANGED
data/lib/deep_unrest.rb
CHANGED
@@ -162,7 +162,7 @@ module DeepUnrest
|
|
162
162
|
def self.parse_attributes(type, scope_type, attributes, user)
|
163
163
|
p = JSONAPI::RequestParser.new
|
164
164
|
resource = get_resource(type)
|
165
|
-
p.
|
165
|
+
p.source_klass = resource
|
166
166
|
ctx = { current_user: user }
|
167
167
|
opts = if scope_type == :create
|
168
168
|
resource.creatable_fields(ctx)
|
@@ -170,7 +170,7 @@ module DeepUnrest
|
|
170
170
|
resource.updatable_fields(ctx)
|
171
171
|
end
|
172
172
|
|
173
|
-
p.parse_params({ attributes: attributes }, opts)[:attributes]
|
173
|
+
p.parse_params(resource, { attributes: attributes }, opts)[:attributes]
|
174
174
|
rescue JSONAPI::Exceptions::ParameterNotAllowed
|
175
175
|
unpermitted_keys = attributes.keys.map(&:to_sym) - opts
|
176
176
|
msg = "Attributes #{unpermitted_keys} of #{type.classify} not allowed"
|
@@ -558,6 +558,19 @@ module DeepUnrest
|
|
558
558
|
DeepUnrest::Write.write(ctx, params, user)
|
559
559
|
end
|
560
560
|
|
561
|
+
def self.serialize_resource(resource_klass, fields, id)
|
562
|
+
resource_identity = JSONAPI::ResourceIdentity.new(resource_klass, id)
|
563
|
+
id_tree = JSONAPI::PrimaryResourceIdTree.new
|
564
|
+
id_tree.add_resource_fragment(JSONAPI::ResourceFragment.new(resource_identity), {})
|
565
|
+
resource_set = JSONAPI::ResourceSet.new(id_tree)
|
566
|
+
serializer = JSONAPI::ResourceSerializer.new(
|
567
|
+
resource_klass,
|
568
|
+
fields: fields
|
569
|
+
)
|
570
|
+
resource_set.populate!(serializer, {}, {})
|
571
|
+
serializer.serialize_resource_set_to_hash_single(resource_set)['data'].except('links')
|
572
|
+
end
|
573
|
+
|
561
574
|
def self.serialize_changes(diffs, user)
|
562
575
|
ctx = { current_user: user }
|
563
576
|
diffs.each do |diff|
|
@@ -582,10 +595,7 @@ module DeepUnrest
|
|
582
595
|
keys = diff[:resource].keys.map(&:to_sym)
|
583
596
|
fields[to_assoc(diff[:klass].to_s.pluralize)] = keys
|
584
597
|
|
585
|
-
|
586
|
-
resource_klass,
|
587
|
-
fields: fields
|
588
|
-
).serialize_to_hash(resource_klass.new(diff[:model], ctx))[:data]
|
598
|
+
serialize_resource(resource_klass, fields, diff[:model].id)
|
589
599
|
end
|
590
600
|
resources.select { |item| item.dig('attributes') }.compact
|
591
601
|
end
|
@@ -692,10 +702,10 @@ module DeepUnrest
|
|
692
702
|
def self.serialize_result(ctx, item)
|
693
703
|
resource = item[:resource]
|
694
704
|
resource_instance = resource.new(item[:record], ctx)
|
695
|
-
fields =
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
).
|
705
|
+
fields = {}
|
706
|
+
keys = item[:query][:fields].map(&:underscore).map(&:to_sym)
|
707
|
+
fields[to_assoc(item[:key].pluralize)] = keys
|
708
|
+
|
709
|
+
serialize_resource(resource, fields, item[:record].id).except(:links)
|
700
710
|
end
|
701
711
|
end
|
data/lib/deep_unrest/read.rb
CHANGED
@@ -102,6 +102,11 @@ module DeepUnrest
|
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
105
|
+
def self.format_processor_results(resource_klass, processor_result)
|
106
|
+
results = processor_result.resource_set.resource_klasses[resource_klass] || {}
|
107
|
+
results.values.map {|r| r[:resource] }
|
108
|
+
end
|
109
|
+
|
105
110
|
def self.query_list(ctx, item, mappings, parent_context, included, meta, addr, parent)
|
106
111
|
base_query = item[:query].deep_dup
|
107
112
|
extension = base_query.dig(:extend, parent&.fetch(:record)&.id&.to_s&.underscore) || {}
|
@@ -122,15 +127,20 @@ module DeepUnrest
|
|
122
127
|
# transform sort value casing for rails
|
123
128
|
sort_criteria = query[:sort]&.map { |s| s.clone.merge(field: s[:field].underscore) }
|
124
129
|
|
130
|
+
serializer = JSONAPI::ResourceSerializer.new(resource)
|
131
|
+
|
125
132
|
processor = JSONAPI::Processor.new(resource,
|
126
133
|
:find,
|
127
134
|
filters: query[:filter] || {},
|
128
135
|
context: ctx,
|
129
136
|
sort_criteria: sort_criteria,
|
137
|
+
serializer: serializer,
|
130
138
|
paginator: paginator)
|
131
139
|
|
132
140
|
jsonapi_result = processor.process
|
133
141
|
|
142
|
+
resource_results = format_processor_results(resource, jsonapi_result)
|
143
|
+
|
134
144
|
# un-monkey patch the resource :records method
|
135
145
|
r_metaclass.send(:alias_method, :records, :records_original)
|
136
146
|
|
@@ -146,14 +156,14 @@ module DeepUnrest
|
|
146
156
|
}
|
147
157
|
|
148
158
|
# make sure to return empty array if no results are found for this node
|
149
|
-
if
|
159
|
+
if resource_results.empty?
|
150
160
|
meta << {
|
151
161
|
addr: [*addr, item[:key], 'data'],
|
152
162
|
serialized_result: []
|
153
163
|
}
|
154
164
|
end
|
155
165
|
|
156
|
-
|
166
|
+
resource_results.each_with_index do |record, i|
|
157
167
|
next_addr = [*addr, item[:key], 'data[]', i]
|
158
168
|
result = {
|
159
169
|
**item,
|
data/lib/deep_unrest/version.rb
CHANGED
data/lib/deep_unrest/write.rb
CHANGED
@@ -3,7 +3,6 @@
|
|
3
3
|
module DeepUnrest
|
4
4
|
module Write
|
5
5
|
def self.get_scope_type(item, path)
|
6
|
-
return :index if DeepUnrest.plural?(path)
|
7
6
|
return :destroy if item[:destroy]
|
8
7
|
return :show if item[:readOnly] || item[:attributes].blank?
|
9
8
|
return :create if item[:id] && DeepUnrest.temp_id?(item[:id].to_s)
|
@@ -74,14 +73,14 @@ module DeepUnrest
|
|
74
73
|
attributes = item.dig(:query, :attributes) || {}
|
75
74
|
resource = item[:resource]
|
76
75
|
p = JSONAPI::RequestParser.new
|
77
|
-
p.
|
76
|
+
p.source_klass = resource
|
78
77
|
opts = if item[:scope_type] == :create
|
79
78
|
resource.creatable_fields(ctx)
|
80
79
|
else
|
81
80
|
resource.updatable_fields(ctx)
|
82
81
|
end
|
83
82
|
|
84
|
-
p.parse_params({ attributes: attributes }, opts)[:attributes]
|
83
|
+
p.parse_params(resource, { attributes: attributes }, opts)[:attributes]
|
85
84
|
rescue JSONAPI::Exceptions::ParameterNotAllowed
|
86
85
|
unpermitted_keys = attributes.keys.map(&:to_sym) - opts
|
87
86
|
item[:errors] = unpermitted_keys.each_with_object({}) do |attr_key, memo|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deep_unrest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.70
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lynn Hurley
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 6.1.3
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 6.1.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: jsonapi-resources
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.
|
33
|
+
version: '0.10'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.
|
40
|
+
version: '0.10'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: sqlite3
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,42 +58,42 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - '='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 2.0.0
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - '='
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 2.0.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: pundit
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - '='
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 2.1.0
|
76
76
|
type: :development
|
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:
|
82
|
+
version: 2.1.0
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: dragonfly
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - '='
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 1.
|
89
|
+
version: 1.3.0
|
90
90
|
type: :development
|
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: 1.
|
96
|
+
version: 1.3.0
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: database_cleaner
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,14 +114,14 @@ dependencies:
|
|
114
114
|
requirements:
|
115
115
|
- - '='
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version:
|
117
|
+
version: 2.18.0
|
118
118
|
type: :development
|
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:
|
124
|
+
version: 2.18.0
|
125
125
|
description: Update multiple or deeply nested JSONAPI resources
|
126
126
|
email:
|
127
127
|
- lynn.dylan.hurley@gmail.com
|
@@ -157,7 +157,7 @@ homepage: https://github.com/graveflex/deep_unrest
|
|
157
157
|
licenses:
|
158
158
|
- MIT
|
159
159
|
metadata: {}
|
160
|
-
post_install_message:
|
160
|
+
post_install_message:
|
161
161
|
rdoc_options: []
|
162
162
|
require_paths:
|
163
163
|
- lib
|
@@ -172,8 +172,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
172
172
|
- !ruby/object:Gem::Version
|
173
173
|
version: '0'
|
174
174
|
requirements: []
|
175
|
-
rubygems_version: 3.
|
176
|
-
signing_key:
|
175
|
+
rubygems_version: 3.2.3
|
176
|
+
signing_key:
|
177
177
|
specification_version: 4
|
178
178
|
summary: Update multiple or deeply nested JSONAPI resources
|
179
179
|
test_files: []
|