typelizer 0.5.1 → 0.5.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: fa25b7b1816ce597e18fd9914b7f9434a4f9cbc4e5e7dcb80c783850a0e3d99c
4
- data.tar.gz: 882d39a7faffcec6d7911c646a5a82a5164be04943c5f109b3c245f03728bcb8
3
+ metadata.gz: d3deaa0f184a8406a1bcca5994b75565a861c32e4afd2af6e7c48643422127f6
4
+ data.tar.gz: d270f2596b33c68d7cd426866618d573c9798648376e66b8e1e0bf76d3967c28
5
5
  SHA512:
6
- metadata.gz: c99a3bc8dd6bbeaeed50394963d5a7081ebf3d1d837c9fa0b3bff6e4bd822974c8953fa355b22b07539736f18f2f7cf7f998e1bb68bdb01785a18bc1a6e5e0b7
7
- data.tar.gz: 7b041dc084316a0ce823150b32c6af5555abacf15aaa99f4a286eec87d4a7f5b7ada172dcf3b45735139574647c91e7e5fe722d5da0a1959305a4e87d093157d
6
+ metadata.gz: 67fcb4958821e25180c5a8493ca1d16b2e9f590959d2ef97f347018e692b3d94b9f084222355db547b1de27b0a9758049e3da391c640553a81aa33a4ab821bda
7
+ data.tar.gz: e1fba11ea9af7e654da8dde504582748a2d1046d15cb52a343895c9453d5e779215bc15f9827fa8604a822b04e2e2acef72f7176f77bd52783df2094e8b68d37
data/CHANGELOG.md CHANGED
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning].
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.5.2] - 2025-11-25
11
+
12
+ ## Fixed
13
+
14
+ - Ignore trace points if they return errors on class checks to fix Rails 8.1 compatibility. ([@skryukov])
15
+
16
+ ## [0.5.2] - 2025-10-06
17
+
18
+ ## Added
19
+
20
+ - Infer type for `<relation>_ids`. ([@skryukov])
21
+
10
22
  ## [0.5.1] - 2025-09-11
11
23
 
12
24
  ### Fixed
@@ -195,7 +207,9 @@ and this project adheres to [Semantic Versioning].
195
207
  [@prog-supdex]: https://github.com/prog-supdex
196
208
  [@ventsislaf]: https://github.com/ventsislaf
197
209
 
198
- [Unreleased]: https://github.com/skryukov/typelizer/compare/v0.5.1...HEAD
210
+ [Unreleased]: https://github.com/skryukov/typelizer/compare/v0.5.3...HEAD
211
+ [0.5.3]: https://github.com/skryukov/typelizer/compare/v0.5.2...v0.5.3
212
+ [0.5.2]: https://github.com/skryukov/typelizer/compare/v0.5.1...v0.5.2
199
213
  [0.5.1]: https://github.com/skryukov/typelizer/compare/v0.5.0...v0.5.1
200
214
  [0.5.0]: https://github.com/skryukov/typelizer/compare/v0.4.2...v0.5.0
201
215
  [0.4.2]: https://github.com/skryukov/typelizer/compare/v0.4.1...v0.4.2
data/README.md CHANGED
@@ -421,7 +421,7 @@ Typelizer.configure do |config|
421
421
 
422
422
  # List of type names that should be considered global in TypeScript
423
423
  # (i.e. not prefixed with the import path)
424
- config.types_global << %w[Array Date Record File FileList]
424
+ config.types_global = %w[Array Date Record File FileList]
425
425
 
426
426
  # Support TypeScript's Verbatim module syntax option (default: false)
427
427
  # Will change imports and exports of types from default to support this syntax option
@@ -46,7 +46,7 @@ module Typelizer
46
46
  files ||= Typelizer.dirs.flat_map { |dir| Dir["#{dir}/**/*.rb"] }
47
47
  files.each do |file|
48
48
  trace = TracePoint.new(:call) do |tp|
49
- next unless tp.self.is_a?(Class) && tp.self.respond_to?(:typelizer_config)
49
+ next unless typelized_class?(tp.self)
50
50
 
51
51
  serializer_plugin = build_scan_plugin_for(tp.self)
52
52
  next unless serializer_plugin
@@ -65,6 +65,12 @@ module Typelizer
65
65
  end
66
66
  end
67
67
 
68
+ def typelized_class?(klass)
69
+ klass.is_a?(Class) && klass.respond_to?(:typelizer_config)
70
+ rescue
71
+ false
72
+ end
73
+
68
74
  # Builds a minimal plugin instance used only during scan time for TracePoint
69
75
  def build_scan_plugin_for(serializer_klass)
70
76
  return @scan_plugin_cache[serializer_klass] if @scan_plugin_cache&.key?(serializer_klass)
@@ -11,6 +11,7 @@ module Typelizer
11
11
  def infer_types(prop)
12
12
  infer_types_for_association(prop) ||
13
13
  infer_types_for_column(prop) ||
14
+ infer_types_for_association_ids(prop) ||
14
15
  infer_types_for_attribute(prop)
15
16
 
16
17
  prop
@@ -84,6 +85,19 @@ module Typelizer
84
85
  prop
85
86
  end
86
87
 
88
+ def infer_types_for_association_ids(prop)
89
+ column_name = prop.column_name.to_s
90
+ return nil unless column_name.end_with?("_ids")
91
+
92
+ base_name = column_name.chomp("_ids").pluralize
93
+ association = model_class&.reflect_on_association(base_name.to_sym)
94
+ return nil unless association
95
+
96
+ prop.type = :number
97
+ prop.multi = true
98
+ prop
99
+ end
100
+
87
101
  def infer_types_for_attribute(prop)
88
102
  return nil unless model_class.respond_to?(:attribute_types)
89
103
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Typelizer
4
- VERSION = "0.5.1"
4
+ VERSION = "0.5.3"
5
5
  end
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.5.1
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Svyatoslav Kryukov
@@ -23,6 +23,20 @@ dependencies:
23
23
  - - ">="
24
24
  - !ruby/object:Gem::Version
25
25
  version: 6.0.0
26
+ - !ruby/object:Gem::Dependency
27
+ name: benchmark
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
26
40
  description: A TypeScript type generator for Ruby serializers.
27
41
  email:
28
42
  - me@skryukov.dev