typed_params 1.2.1 → 1.2.3

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: f82d6c1b5e74e9768d4e039ffdb562d4f4358a3cacdcaa6bbd7c88fa2f052b98
4
- data.tar.gz: a2635ee1541b834a73cefed0768f15e9d47d435af3b3d27cb497d0d4e98bb18a
3
+ metadata.gz: f94106e5442d1a47d16c72246e4dd91a981a6bc574b2c341983c70d2407a252f
4
+ data.tar.gz: 28935e7de711ac1d8ef7b53ad46bc673b06a3537667d845adc9561b927f95a02
5
5
  SHA512:
6
- metadata.gz: 6dfb4c39029e273c58a08459b2c7fc2b5263947816d15bcb4a3e8d3e8b9bd2b7ca56b487f40b8d84a4bd391b6cf7913717be2c62e7d38548e8f8cea4c93e4ec8
7
- data.tar.gz: 444e92938c7426fec891eda9f7dd226861296f6159c1e8905d6776d2fee75c95f20ce762358161c36970bf84ceadbc352d0bfdfb6c7f56f9c1d350934ba86649
6
+ metadata.gz: 87fcccc2315b7216cd2e4d2e24c413fbf3e482bd4f49df486afed6335312dc19226bd72cf90665e23134b26ed8bab34bae9f4f3eb93720dc405790db3f3290dd
7
+ data.tar.gz: 3dd050bb4b2d4a8a01a434b8c44599b14e23bd9a0aec353d80cad127925f378177d63f3e5f58d736a33d40120ed3828217bfcd355f704e91d77e9ade49693b2c
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.2.3
4
+
5
+ - Remove `alias` from child lookup criteria in JSONAPI serializer.
6
+
7
+ ## 1.2.2
8
+
9
+ - Fix issue where `as:` keyword was not handled in JSONAPI relationship formatter.
10
+
3
11
  ## 1.2.1
4
12
 
5
13
  - Update JSONAPI formatter to simplify logic for polymorphic relationships.
@@ -58,9 +58,10 @@ module TypedParams
58
58
  end
59
59
 
60
60
  def self.format_hash_data(data, schema:)
61
- rels = data[:relationships]
62
- attrs = data[:attributes]
63
- res = data.except(
61
+ relationships = data[:relationships]
62
+ attributes = data[:attributes]
63
+
64
+ res = data.except(
64
65
  :attributes,
65
66
  :links,
66
67
  :meta,
@@ -69,18 +70,21 @@ module TypedParams
69
70
  )
70
71
 
71
72
  # Move attributes over to top-level params
72
- attrs&.each do |key, attr|
73
- res[key] = attr
73
+ attributes&.each do |key, attribute|
74
+ res[key] = attribute
74
75
  end
75
76
 
76
77
  # Move relationships over. This will use x_id and x_ids when the
77
78
  # relationship data only contains :type and :id, otherwise it
78
79
  # will use the x_attributes key.
79
- rels&.each do |key, rel|
80
- child = schema.children.fetch(:relationships)
81
- .children.fetch(key)
82
-
83
- case rel
80
+ relationships&.each do |key, relationship|
81
+ child = schema.children.fetch(:relationships).then do |rels|
82
+ rels.children.fetch(key) {
83
+ rels.children.values.find { _1.as == key }
84
+ }
85
+ end
86
+
87
+ case relationship
84
88
  # FIXME(ezekg) We need https://bugs.ruby-lang.org/issues/18961 to
85
89
  # clean this up (i.e. remove the if guard).
86
90
  in data: [{ type:, id:, **nil }, *] => linkage if linkage.all? { _1 in type:, id:, **nil }
@@ -96,7 +100,7 @@ module TypedParams
96
100
  else
97
101
  # NOTE(ezekg) Embedded relationships are non-standard as per the
98
102
  # JSONAPI spec, but I don't really care. :)
99
- res[:"#{key}_attributes"] = call(rel, schema: child)
103
+ res[:"#{key}_attributes"] = call(relationship, schema: child)
100
104
  end
101
105
  end
102
106
 
@@ -10,6 +10,7 @@ module TypedParams
10
10
  :source,
11
11
  :type,
12
12
  :key,
13
+ :as,
13
14
  :alias,
14
15
  :if,
15
16
  :unless
@@ -80,6 +81,7 @@ module TypedParams
80
81
  @strict = strict
81
82
  @parent = parent
82
83
  @key = key
84
+ @as = as
83
85
  @alias = binding.local_variable_get(:alias)
84
86
  @optional = optional
85
87
  @coerce = coerce && @type.coercable?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TypedParams
4
- VERSION = '1.2.1'
4
+ VERSION = '1.2.3'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: typed_params
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zeke Gabrielse