typelizer 0.4.0 → 0.4.1

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: ed3e7b6339e4a79168c10afd541bba9ea8c509b00f689465df037501327ac6e2
4
- data.tar.gz: a7f079a7ad377d1f2754cc1efcb98a7bc0e8af11c3910e8f56b648090ddb7f46
3
+ metadata.gz: 067c0e093a70b8c8273e7504004a687c08272a536367958662e9d7c2fe293151
4
+ data.tar.gz: 6dc5ef91af5f50ead351f90ee6cf8026360f1f605d06df5a30e20a9633ec168b
5
5
  SHA512:
6
- metadata.gz: 7687ff8e061c46e11f56421684a5629a823debc4d76ac3018e3ab7ac960416a05088662372b38bb4029a650ba6d81c74fbccb49d9821d7864f86023fdddd819e
7
- data.tar.gz: 860d8dc24a04302c2e70d30a4ef6811f595ee4e55788ab47d6966c10a405370dc756419b06e15b343b00fc38d495897e706d5be5a5fb1816b9a0da3315c009ce
6
+ metadata.gz: b518818c82709eea2ef5461272c929189d0fa59f53aa3f1cb6309e538ffe586b0bd2117cd520a165def41221f9f05528caf934842584f840f64370ce035488a9
7
+ data.tar.gz: c89f29ad82e7fa44f3118385ccbd8a6ffb5fde9bbe1d3e400994704fdb8a709ccb9b22f029332cd36da6bdc3c8b190b5c0cf1c9492fa5e11cda4ad7d082c8898
data/CHANGELOG.md CHANGED
@@ -5,6 +5,21 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog],
6
6
  and this project adheres to [Semantic Versioning].
7
7
 
8
+ ## [Unreleased]
9
+
10
+ ## [0.4.1] - 2025-06-10
11
+
12
+ ### Added
13
+
14
+ - Add option to use double quotes in generated TypeScript interfaces through `prefer_double_quotes` config option ([@kristinemcbride])
15
+
16
+ ### Fixed
17
+
18
+ - Fix types not being generated on the fly since [0.2.0]. ([@skryukov])
19
+ - Improve memory consumption (~100x less memory) & speed of types generation (~5x faster). ([@skryukov])
20
+ - Fix nullable detection for `belongs_to` associations with `:active_record` strategy. ([@NOX73])
21
+ - Alba: fix unknown type for conditional attribute with `transform_keys`. ([@nkriege])
22
+
8
23
  ## [0.4.0] - 2025-05-03
9
24
 
10
25
  ### Added
@@ -35,7 +50,7 @@ and this project adheres to [Semantic Versioning].
35
50
  admin_level: number;
36
51
  }
37
52
  ```
38
-
53
+
39
54
  ### Fixed
40
55
 
41
56
  - Alba: always use strings for keys in properties. ([@skryukov])
@@ -146,11 +161,15 @@ and this project adheres to [Semantic Versioning].
146
161
 
147
162
  [@davidrunger]: https://github.com/davidrunger
148
163
  [@Envek]: https://github.com/Envek
164
+ [@kristinemcbride]: https://github.com/kristinemcbride
165
+ [@nkriege]: https://github.com/nkriege
166
+ [@NOX73]: https://github.com/NOX73
149
167
  [@okuramasafumi]: https://github.com/okuramasafumi
150
168
  [@patvice]: https://github.com/patvice
151
169
  [@skryukov]: https://github.com/skryukov
152
170
 
153
- [Unreleased]: https://github.com/skryukov/typelizer/compare/v0.4.0...HEAD
171
+ [Unreleased]: https://github.com/skryukov/typelizer/compare/v0.4.1...HEAD
172
+ [0.4.1]: https://github.com/skryukov/typelizer/compare/v0.4.0...v0.4.1
154
173
  [0.4.0]: https://github.com/skryukov/typelizer/compare/v0.3.0...v0.4.0
155
174
  [0.3.0]: https://github.com/skryukov/typelizer/compare/v0.2.0...v0.3.0
156
175
  [0.2.0]: https://github.com/skryukov/typelizer/compare/v0.1.5...v0.2.0
data/README.md CHANGED
@@ -281,6 +281,9 @@ Typelizer.configure do |config|
281
281
  # Will change imports and exports of types from default to support this syntax option
282
282
  config.verbatim_module_syntax = false
283
283
 
284
+ # Use double quotes in generated TypeScript interfaces (default: false)
285
+ config.prefer_double_quotes = false
286
+
284
287
  # Support comments in generated TypeScript interfaces (default: false)
285
288
  # Will add comments to the generated interfaces
286
289
  config.comments = false
@@ -28,6 +28,7 @@ module Typelizer
28
28
  :inheritance_strategy,
29
29
  :associations_strategy,
30
30
  :comments,
31
+ :prefer_double_quotes,
31
32
  keyword_init: true
32
33
  ) do
33
34
  class << self
@@ -52,6 +53,7 @@ module Typelizer
52
53
  inheritance_strategy: :none,
53
54
  associations_strategy: :database,
54
55
  comments: false,
56
+ prefer_double_quotes: false,
55
57
 
56
58
  output_dir: js_root.join("types/serializers"),
57
59
 
@@ -16,16 +16,14 @@ module Typelizer
16
16
  def call(force: false)
17
17
  return unless Typelizer.enabled?
18
18
 
19
- writer.call(interfaces, force: force)
20
-
21
- interfaces
19
+ found_interfaces = interfaces
20
+ writer.call(found_interfaces, force: force)
21
+ found_interfaces
22
22
  end
23
23
 
24
24
  def interfaces
25
- @interfaces ||= begin
26
- read_serializers
27
- target_serializers.map(&:typelizer_interface).reject(&:empty?)
28
- end
25
+ read_serializers
26
+ target_serializers.map(&:typelizer_interface).reject(&:empty?)
29
27
  end
30
28
 
31
29
  private
@@ -44,14 +42,10 @@ module Typelizer
44
42
 
45
43
  def read_serializers(files = nil)
46
44
  files ||= Typelizer.dirs.flat_map { |dir| Dir["#{dir}/**/*.rb"] }
47
-
48
45
  files.each do |file|
49
46
  trace = TracePoint.new(:call) do |tp|
50
- begin
51
- next unless tp.self.methods.include?(:typelizer_interface)
52
- rescue WeakRef::RefError
53
- next
54
- end
47
+ next unless tp.self.is_a?(Class) && tp.self.respond_to?(:typelizer_interface) && tp.self.typelizer_interface.is_a?(Interface)
48
+
55
49
  serializer_plugin = tp.self.typelizer_interface.serializer_plugin
56
50
 
57
51
  if tp.callee_id.in?(serializer_plugin.methods_to_typelize)
@@ -103,6 +103,10 @@ module Typelizer
103
103
  "<#{self.class.name} #{name} properties=[#{properties_to_print.map(&:fingerprint).join(", ")}]>"
104
104
  end
105
105
 
106
+ def quote(str)
107
+ config.prefer_double_quotes ? "\"#{str}\"" : "'#{str}'"
108
+ end
109
+
106
110
  private
107
111
 
108
112
  def self_type_name
@@ -17,7 +17,7 @@ module Typelizer
17
17
  if config.associations_strategy == :database
18
18
  prop.nullable = column.null if column
19
19
  elsif config.associations_strategy == :active_record
20
- prop.nullable = !association.options[:required] || association.options[:optional]
20
+ prop.nullable = association.options[:optional] === true || association.options[:required] === false
21
21
  else
22
22
  raise "Unknown associations strategy: #{config.associations_strategy}"
23
23
  end
@@ -24,8 +24,10 @@ module Typelizer
24
24
  end
25
25
 
26
26
  def fingerprint
27
- props = to_h.merge(type: type_name).reject { |_, v| v.nil? }.map { |k, v| "#{k}=#{v.inspect}" }.join(" ")
28
- "<#{self.class.name} #{props}>"
27
+ props = to_h
28
+ props[:type] = type_name
29
+ props = props.filter_map { |k, v| "#{k}=#{v.inspect}" unless v.nil? }
30
+ "<#{self.class.name} #{props.join(" ")}>"
29
31
  end
30
32
 
31
33
  private
@@ -124,7 +124,7 @@ module Typelizer
124
124
  **options
125
125
  )
126
126
  when ::Alba::ConditionalAttribute
127
- build_property(name, attr.instance_variable_get(:@body), optional: true)
127
+ build_property(column_name, attr.instance_variable_get(:@body), optional: true)
128
128
  else
129
129
  raise ArgumentError, "Unsupported attribute type: #{attr.class}"
130
130
  end
@@ -1,7 +1,7 @@
1
1
  <%- interfaces.each do |interface| -%>
2
2
  <%- if interface.config.verbatim_module_syntax -%>
3
- export type { <%= interface.name %> } from './<%= interface.filename %>'
3
+ export type { <%= interface.name %> } from <%= interface.quote('./' + interface.filename) %>
4
4
  <%- else -%>
5
- export type { default as <%= interface.name %> } from './<%= interface.filename %>'
6
- <%- end -%>
5
+ export type { default as <%= interface.name %> } from <%= interface.quote('./' + interface.filename) %>
7
6
  <%- end -%>
7
+ <%- end -%>
@@ -1 +1 @@
1
- <%= interface.overwritten_properties.any? ? "Omit<" : "" %><%= interface.parent_interface.name %><%= "['#{interface.parent_interface.root_key}']" if interface.parent_interface.root_key %><%= interface.overwritten_properties.any? ? ", " + interface.overwritten_properties.map { |pr| "'#{pr.name}'" }.join(' | ') + ">" : ""%>
1
+ <%= interface.overwritten_properties.any? ? "Omit<" : "" %><%= interface.parent_interface.name %><%= "[" + interface.quote(interface.parent_interface.root_key) + "]" if interface.parent_interface.root_key %><%= interface.overwritten_properties.any? ? ", " + interface.overwritten_properties.map { |pr| interface.quote(pr.name) }.join(' | ') + ">" : ""%>
@@ -1,5 +1,5 @@
1
1
  <% if interface.imports.any? -%>
2
- import type {<%= interface.imports.join(", ") %>} from '<%= interface.config.types_import_path %>'
2
+ import type {<%= interface.imports.join(", ") %>} from <%= interface.quote(interface.config.types_import_path) %>
3
3
  <% end -%>
4
4
 
5
5
  type <%= interface.name %><%= "Data" if interface.root_key %> = <%=
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Typelizer
4
- VERSION = "0.4.0"
4
+ VERSION = "0.4.1"
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: typelizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Svyatoslav Kryukov
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-05-02 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: railties
@@ -83,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
83
  - !ruby/object:Gem::Version
84
84
  version: '0'
85
85
  requirements: []
86
- rubygems_version: 3.6.2
86
+ rubygems_version: 3.6.7
87
87
  specification_version: 4
88
88
  summary: A TypeScript type generator for Ruby serializers.
89
89
  test_files: []