typelizer 0.4.0 → 0.4.2
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 +4 -4
- data/CHANGELOG.md +33 -2
- data/README.md +3 -0
- data/lib/typelizer/config.rb +4 -1
- data/lib/typelizer/generator.rb +7 -13
- data/lib/typelizer/interface.rb +4 -0
- data/lib/typelizer/model_plugins/active_record.rb +1 -1
- data/lib/typelizer/property.rb +4 -2
- data/lib/typelizer/serializer_plugins/alba.rb +2 -2
- data/lib/typelizer/templates/index.ts.erb +3 -3
- data/lib/typelizer/templates/inheritance.ts.erb +1 -1
- data/lib/typelizer/templates/interface.ts.erb +1 -1
- data/lib/typelizer/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: a41914a150239acf4de1b43149a0bfaa81c9511a6a5434aa445cfc9dbf3ee343
|
4
|
+
data.tar.gz: 82d1616845d782c041466d8500453afb8052a3d4fd8ce4e6f63c045c41a19544
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f51fef6373b00d177faceccebc84c87e22f428f684990aa3faa762a5cabca853cf609c7476f98cc34ce26d1737ace2f258c47099a23018755f3e595873009d1
|
7
|
+
data.tar.gz: fff6bc2ca1844cc45d7d7a2a6bf8ac269078243013acb4e83ead8a902936f62fcfd5e15a96fbcbb1289266c52f53446e4cb3fa74584eeef09ab86882eadcfc43
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,31 @@ 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.2] - 2025-06-23
|
11
|
+
|
12
|
+
### Added
|
13
|
+
|
14
|
+
- Map `uuid` type to `string` by default. ([@ventsislaf])
|
15
|
+
|
16
|
+
### Fixed
|
17
|
+
|
18
|
+
- Alba: fix `has_many` with a custom `key` generates single value type instead of array. ([@skryukov])
|
19
|
+
|
20
|
+
## [0.4.1] - 2025-06-10
|
21
|
+
|
22
|
+
### Added
|
23
|
+
|
24
|
+
- Add option to use double quotes in generated TypeScript interfaces through `prefer_double_quotes` config option ([@kristinemcbride])
|
25
|
+
|
26
|
+
### Fixed
|
27
|
+
|
28
|
+
- Fix types not being generated on the fly since [0.2.0]. ([@skryukov])
|
29
|
+
- Improve memory consumption (~100x less memory) & speed of types generation (~5x faster). ([@skryukov])
|
30
|
+
- Fix nullable detection for `belongs_to` associations with `:active_record` strategy. ([@NOX73])
|
31
|
+
- Alba: fix unknown type for conditional attribute with `transform_keys`. ([@nkriege])
|
32
|
+
|
8
33
|
## [0.4.0] - 2025-05-03
|
9
34
|
|
10
35
|
### Added
|
@@ -35,7 +60,7 @@ and this project adheres to [Semantic Versioning].
|
|
35
60
|
admin_level: number;
|
36
61
|
}
|
37
62
|
```
|
38
|
-
|
63
|
+
|
39
64
|
### Fixed
|
40
65
|
|
41
66
|
- Alba: always use strings for keys in properties. ([@skryukov])
|
@@ -146,11 +171,17 @@ and this project adheres to [Semantic Versioning].
|
|
146
171
|
|
147
172
|
[@davidrunger]: https://github.com/davidrunger
|
148
173
|
[@Envek]: https://github.com/Envek
|
174
|
+
[@kristinemcbride]: https://github.com/kristinemcbride
|
175
|
+
[@nkriege]: https://github.com/nkriege
|
176
|
+
[@NOX73]: https://github.com/NOX73
|
149
177
|
[@okuramasafumi]: https://github.com/okuramasafumi
|
150
178
|
[@patvice]: https://github.com/patvice
|
151
179
|
[@skryukov]: https://github.com/skryukov
|
180
|
+
[@ventsislaf]: https://github.com/ventsislaf
|
152
181
|
|
153
|
-
[Unreleased]: https://github.com/skryukov/typelizer/compare/v0.4.
|
182
|
+
[Unreleased]: https://github.com/skryukov/typelizer/compare/v0.4.2...HEAD
|
183
|
+
[0.4.2]: https://github.com/skryukov/typelizer/compare/v0.4.1...v0.4.2
|
184
|
+
[0.4.1]: https://github.com/skryukov/typelizer/compare/v0.4.0...v0.4.1
|
154
185
|
[0.4.0]: https://github.com/skryukov/typelizer/compare/v0.3.0...v0.4.0
|
155
186
|
[0.3.0]: https://github.com/skryukov/typelizer/compare/v0.2.0...v0.3.0
|
156
187
|
[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
|
data/lib/typelizer/config.rb
CHANGED
@@ -7,7 +7,8 @@ module Typelizer
|
|
7
7
|
integer: :number,
|
8
8
|
string: :string,
|
9
9
|
text: :string,
|
10
|
-
citext: :string
|
10
|
+
citext: :string,
|
11
|
+
uuid: :string
|
11
12
|
}.tap do |types|
|
12
13
|
types.default = :unknown
|
13
14
|
end
|
@@ -28,6 +29,7 @@ module Typelizer
|
|
28
29
|
:inheritance_strategy,
|
29
30
|
:associations_strategy,
|
30
31
|
:comments,
|
32
|
+
:prefer_double_quotes,
|
31
33
|
keyword_init: true
|
32
34
|
) do
|
33
35
|
class << self
|
@@ -52,6 +54,7 @@ module Typelizer
|
|
52
54
|
inheritance_strategy: :none,
|
53
55
|
associations_strategy: :database,
|
54
56
|
comments: false,
|
57
|
+
prefer_double_quotes: false,
|
55
58
|
|
56
59
|
output_dir: js_root.join("types/serializers"),
|
57
60
|
|
data/lib/typelizer/generator.rb
CHANGED
@@ -16,16 +16,14 @@ module Typelizer
|
|
16
16
|
def call(force: false)
|
17
17
|
return unless Typelizer.enabled?
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
found_interfaces = interfaces
|
20
|
+
writer.call(found_interfaces, force: force)
|
21
|
+
found_interfaces
|
22
22
|
end
|
23
23
|
|
24
24
|
def interfaces
|
25
|
-
|
26
|
-
|
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
|
-
|
51
|
-
|
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)
|
data/lib/typelizer/interface.rb
CHANGED
@@ -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 =
|
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
|
data/lib/typelizer/property.rb
CHANGED
@@ -24,8 +24,10 @@ module Typelizer
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def fingerprint
|
27
|
-
props = to_h
|
28
|
-
|
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
|
@@ -98,7 +98,7 @@ module Typelizer
|
|
98
98
|
optional: false,
|
99
99
|
nullable: false,
|
100
100
|
multi: false, # we override this in typelize_method_transform
|
101
|
-
column_name:
|
101
|
+
column_name: attr.name.is_a?(Symbol) ? attr.name.name : attr.name,
|
102
102
|
**options
|
103
103
|
)
|
104
104
|
when ::Alba::TypedAttribute
|
@@ -124,7 +124,7 @@ module Typelizer
|
|
124
124
|
**options
|
125
125
|
)
|
126
126
|
when ::Alba::ConditionalAttribute
|
127
|
-
build_property(
|
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 '
|
3
|
+
export type { <%= interface.name %> } from <%= interface.quote('./' + interface.filename) %>
|
4
4
|
<%- else -%>
|
5
|
-
export type { default as <%= interface.name %> } from '
|
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 %><%= "[
|
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
|
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 %> = <%=
|
data/lib/typelizer/version.rb
CHANGED
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.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Svyatoslav Kryukov
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date:
|
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.
|
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: []
|