types_from_serializers 2.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/lib/types_from_serializers/generator.rb +8 -9
- data/lib/types_from_serializers/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e3961bc80ddc72831c77e7cf9ddf0959809a49a845f0d778d0c6ac50148cb87
|
4
|
+
data.tar.gz: e676ddfe4c4c51081075bd5bbb3a66990d8ea469dc60305a550175abe8c43c99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01e286a9381c3d8f2e00c4085ba491ab4d4332ee3ac0ea2ebd109a7ff53ddb131b43d1c0839a09459884edc0536cd805d5303be2a80143a12998d6b5839dfc14
|
7
|
+
data.tar.gz: a3687e203f27c34a3243f1422588bd2c79362ef4b7f9c2432ec6ce53493c83c11782f784f8acb4a76d7a611fab6ca7e9422f63560c3053739e3b39c3258d91ed
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
# [2.2.0](https://github.com/ElMassimo/types_from_serializers/compare/types_from_serializers@2.1.0...types_from_serializers@2.2.0) (2024-08-23)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* be more accurate regarding decimal serialization ([cd63653](https://github.com/ElMassimo/types_from_serializers/commit/cd636530a5710112a14746cc7d0e3f15016cd5e1))
|
7
|
+
|
8
|
+
|
9
|
+
### Features
|
10
|
+
|
11
|
+
* infer type from enums ([#20](https://github.com/ElMassimo/types_from_serializers/issues/20)) ([49dc61d](https://github.com/ElMassimo/types_from_serializers/commit/49dc61da2718256e9b5f5743b5a65c4746d64c2f))
|
12
|
+
|
13
|
+
|
14
|
+
|
1
15
|
# [2.1.0](https://github.com/ElMassimo/types_from_serializers/compare/types_from_serializers@2.0.2...types_from_serializers@2.1.0) (2023-07-19)
|
2
16
|
|
3
17
|
|
@@ -38,15 +38,12 @@ module TypesFromSerializers
|
|
38
38
|
TypesFromSerializers.config.name_from_serializer.call(name).gsub("::", "/")
|
39
39
|
end
|
40
40
|
|
41
|
-
# Internal: The columns corresponding to the serializer model, if it's a
|
42
|
-
# record.
|
43
|
-
def model_columns
|
44
|
-
@model_columns ||= _serializer_model_name&.to_model.try(:columns_hash) || {}
|
45
|
-
end
|
46
|
-
|
47
41
|
# Internal: The TypeScript properties of the serialzeir interface.
|
48
42
|
def ts_properties
|
49
43
|
@ts_properties ||= begin
|
44
|
+
model_class = _serializer_model_name&.to_model
|
45
|
+
model_columns = model_class.try(:columns_hash) || {}
|
46
|
+
model_enums = model_class.try(:defined_enums) || {}
|
50
47
|
types_from = try(:_serializer_types_from)
|
51
48
|
|
52
49
|
prepare_attributes(
|
@@ -64,7 +61,7 @@ module TypesFromSerializers
|
|
64
61
|
multi: options[:association] == :many,
|
65
62
|
column_name: options.fetch(:value_from),
|
66
63
|
).tap do |property|
|
67
|
-
property.infer_type_from(model_columns, types_from)
|
64
|
+
property.infer_type_from(model_columns, model_enums, types_from)
|
68
65
|
end
|
69
66
|
end
|
70
67
|
}
|
@@ -190,9 +187,11 @@ module TypesFromSerializers
|
|
190
187
|
|
191
188
|
# Internal: Infers the property's type by checking a corresponding SQL
|
192
189
|
# column, or falling back to a TypeScript interface if provided.
|
193
|
-
def infer_type_from(columns_hash, ts_interface)
|
190
|
+
def infer_type_from(columns_hash, defined_enums, ts_interface)
|
194
191
|
if type
|
195
192
|
type
|
193
|
+
elsif (enum = defined_enums[column_name.to_s])
|
194
|
+
self.type = enum.keys.map(&:inspect).join(" | ")
|
196
195
|
elsif (column = columns_hash[column_name.to_s])
|
197
196
|
self.multi = true if column.try(:array)
|
198
197
|
self.optional = true if column.null && !column.default
|
@@ -383,7 +382,7 @@ module TypesFromSerializers
|
|
383
382
|
boolean: :boolean,
|
384
383
|
date: "string | Date",
|
385
384
|
datetime: "string | Date",
|
386
|
-
decimal:
|
385
|
+
decimal: "string | number",
|
387
386
|
integer: :number,
|
388
387
|
string: :string,
|
389
388
|
text: :string,
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: types_from_serializers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Máximo Mussini
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-08-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -277,7 +277,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
277
277
|
- !ruby/object:Gem::Version
|
278
278
|
version: '0'
|
279
279
|
requirements: []
|
280
|
-
rubygems_version: 3.
|
280
|
+
rubygems_version: 3.4.10
|
281
281
|
signing_key:
|
282
282
|
specification_version: 4
|
283
283
|
summary: Generate TypeScript interfaces from your JSON serializers.
|