typelizer 0.14.0 → 0.15.0

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: 8810d416e08a0541a844bf7e538fbd66999f1ab5e0b6209d5e7c071b06c58fdf
4
- data.tar.gz: 725952a78be5d5f3e13d10e876badfc2be72e848af6bfd2a8063b0f34d0b28c8
3
+ metadata.gz: 6f1a3eec70cb7c226441194e16ed081b2898466dc1ab1ac7dea3dfeebc1fd3bd
4
+ data.tar.gz: dbc20344b6cabd942c45d9334a7e374e62107c04dd756d84fa1495e68bb050a0
5
5
  SHA512:
6
- metadata.gz: a6e833349308d44de700a56865f948f8fa1a2d352acf23d34ab6d9fe22c548ceeef70d566fb78e700f985334f3eb40cabbe8542900b792b6966b98a7e3c07698
7
- data.tar.gz: a6570c070f5b20876814b47045862e2aeeba6589bbd0c6220b43d958f9d46f93e08d54fa3aa1fdc81f74bc874d86acd3f5fe5bc9d4fb4ba7d828534a7ae31c0e
6
+ metadata.gz: 3c82931cc7b7a9a89da19e3ee28e09e5ca50c84842b0aed6c5a4e991b692a7cb9923009f3510ea7e067489cbd994d6b8482889f18c33bed96e8bd4b1ec4724d6
7
+ data.tar.gz: e3360969ba9bb962a4809a93fb01285891b3da0e6c9ecd12130154678755513e7e1d4b25cb9ad0f19d2f379d5f3670caf8765aba97fe61c62df243add1efc8ca
data/CHANGELOG.md CHANGED
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning].
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.15.0] - 2026-11-16
11
+
12
+ ### Changed
13
+
14
+ - **[BREAKING]** Enum types of namespaced models keep the namespace: `Course::Build` with a `state` enum gives `CourseBuildState`, not `BuildState`. Models with the same class name no longer overwrite each other's enums. ([@skryukov])
15
+
16
+ ### Fixed
17
+
18
+ - Panko 1.0 support. ([@benjaminwols])
19
+
10
20
  ## [0.14.0] - 2026-10-03
11
21
 
12
22
  ### Added
@@ -515,6 +525,7 @@ and this project adheres to [Semantic Versioning].
515
525
 
516
526
  - Initial release ([@skryukov])
517
527
 
528
+ [@benjaminwols]: https://github.com/benjaminwols
518
529
  [@davidrunger]: https://github.com/davidrunger
519
530
  [@Envek]: https://github.com/Envek
520
531
  [@hkamberovic]: https://github.com/hkamberovic
@@ -535,7 +546,8 @@ and this project adheres to [Semantic Versioning].
535
546
  [@ventsislaf]: https://github.com/ventsislaf
536
547
  [@visini]: https://github.com/visini
537
548
 
538
- [Unreleased]: https://github.com/skryukov/typelizer/compare/v0.14.0...HEAD
549
+ [Unreleased]: https://github.com/skryukov/typelizer/compare/v0.15.0...HEAD
550
+ [0.15.0]: https://github.com/skryukov/typelizer/compare/v0.14.0...v0.15.0
539
551
  [0.14.0]: https://github.com/skryukov/typelizer/compare/v0.13.1...v0.14.0
540
552
  [0.13.1]: https://github.com/skryukov/typelizer/compare/v0.13.0...v0.13.1
541
553
  [0.13.0]: https://github.com/skryukov/typelizer/compare/v0.12.0...v0.13.0
@@ -31,7 +31,7 @@ module Typelizer
31
31
  return unless model_class&.defined_enums&.key?(prop.column_name.to_s)
32
32
 
33
33
  prop.enum = model_class.defined_enums[prop.column_name.to_s].keys
34
- prop.enum_type_name = "#{model_class.name.demodulize}#{prop.column_name.to_s.camelize}"
34
+ prop.enum_type_name = "#{model_class.name.delete(":")}#{prop.column_name.to_s.camelize}"
35
35
  prop.enum
36
36
  end
37
37
 
@@ -4,46 +4,78 @@ module Typelizer
4
4
  module SerializerPlugins
5
5
  class Panko < Base
6
6
  def properties
7
- descriptor = serializer.new.instance_variable_get(:@descriptor)
8
- attributes = descriptor.attributes
9
- methods_attributes = descriptor.method_fields
10
- has_many_associations = descriptor.has_many_associations
11
- has_one_associations = descriptor.has_one_associations
12
-
13
- attributes.map do |att|
14
- attribute_property(att)
15
- end + methods_attributes.map do |att|
16
- attribute_property(att)
17
- end + has_many_associations.map do |assoc|
18
- association_property(assoc, multi: true)
19
- end + has_one_associations.map do |assoc|
20
- association_property(assoc, multi: false)
7
+ if public_descriptor?
8
+ properties_from_public_descriptor
9
+ else
10
+ properties_from_internal_descriptor
21
11
  end
22
12
  end
23
13
 
24
14
  private
25
15
 
26
- def attribute_property(att)
16
+ def public_descriptor?
17
+ defined?(::Panko::Descriptor)
18
+ end
19
+
20
+ def properties_from_public_descriptor
21
+ # The instance descriptor applies the class-level `filters_for`, as Panko < 1.0 did
22
+ descriptor = serializer.new.descriptor
23
+
24
+ attributes = (descriptor.attributes + descriptor.method_attributes).map do |att|
25
+ build_attribute_property(name: att.name.to_s, column_name: (att.source || att.name).to_s)
26
+ end
27
+
28
+ # has_many before has_one, matching the property order of Panko < 1.0
29
+ has_many, has_one = descriptor.associations.partition { |assoc| assoc.kind == :has_many }
30
+ associations = (has_many + has_one).map do |assoc|
31
+ build_association_property(
32
+ name: assoc.name.to_s,
33
+ serializer: assoc.descriptor.serializer,
34
+ multi: assoc.kind == :has_many
35
+ )
36
+ end
37
+
38
+ attributes + associations
39
+ end
40
+
41
+ # Panko < 1.0 keeps its descriptor in an instance variable of the C extension
42
+ def properties_from_internal_descriptor
43
+ descriptor = serializer.new.instance_variable_get(:@descriptor)
44
+
45
+ attributes = (descriptor.attributes + descriptor.method_fields).map do |att|
46
+ build_attribute_property(name: att.alias_name || att.name, column_name: att.name)
47
+ end
48
+
49
+ has_many = descriptor.has_many_associations.map do |assoc|
50
+ build_association_property(name: assoc.name_str, serializer: assoc.descriptor.type, multi: true)
51
+ end
52
+
53
+ has_one = descriptor.has_one_associations.map do |assoc|
54
+ build_association_property(name: assoc.name_str, serializer: assoc.descriptor.type, multi: false)
55
+ end
56
+
57
+ attributes + has_many + has_one
58
+ end
59
+
60
+ def build_attribute_property(name:, column_name:)
27
61
  Property.new(
28
- name: att.alias_name || att.name,
62
+ name: name,
29
63
  optional: false,
30
64
  nullable: false,
31
65
  multi: false,
32
- column_name: att.name
66
+ column_name: column_name
33
67
  )
34
68
  end
35
69
 
36
- def association_property(assoc, multi: false)
37
- key = assoc.name_str
38
- serializer = assoc.descriptor.type
70
+ def build_association_property(name:, serializer:, multi:)
39
71
  type = serializer ? context.interface_for(serializer) : nil
40
72
  Property.new(
41
- name: key,
73
+ name: name,
42
74
  type: type,
43
75
  optional: false,
44
76
  nullable: false,
45
77
  multi: multi,
46
- column_name: key
78
+ column_name: name
47
79
  )
48
80
  end
49
81
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Typelizer
4
- VERSION = "0.14.0"
4
+ VERSION = "0.15.0"
5
5
  end
@@ -53,10 +53,13 @@ module Typelizer
53
53
  end
54
54
 
55
55
  def collect_enums(interfaces)
56
- interfaces
57
- .flat_map(&:enum_types)
58
- .uniq(&:enum_type_name)
59
- .sort_by(&:enum_type_name)
56
+ interfaces.flat_map(&:enum_types).group_by(&:enum_type_name).sort.map do |name, enums|
57
+ if enums.map { |enum| enum.enum.to_set }.uniq.size > 1
58
+ Typelizer.logger.warn("Typelizer: enum type #{name} has conflicting values, only the first is generated")
59
+ end
60
+
61
+ enums.first
62
+ end
60
63
  end
61
64
 
62
65
  def write_enums(enums)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: typelizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.0
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Svyatoslav Kryukov
@@ -126,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
126
  - !ruby/object:Gem::Version
127
127
  version: '0'
128
128
  requirements: []
129
- rubygems_version: 3.6.9
129
+ rubygems_version: 4.0.20
130
130
  specification_version: 4
131
131
  summary: A TypeScript type generator for Ruby serializers.
132
132
  test_files: []