typelizer 0.3.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 +4 -4
- data/CHANGELOG.md +55 -1
- data/README.md +18 -1
- data/lib/typelizer/config.rb +6 -0
- data/lib/typelizer/generator.rb +7 -13
- data/lib/typelizer/interface.rb +42 -12
- data/lib/typelizer/model_plugins/active_record.rb +24 -0
- data/lib/typelizer/model_plugins/poro.rb +1 -1
- data/lib/typelizer/property.rb +10 -2
- data/lib/typelizer/renderer.rb +8 -0
- data/lib/typelizer/serializer_plugins/alba.rb +2 -2
- data/lib/typelizer/serializer_plugins/auto.rb +2 -0
- data/lib/typelizer/serializer_plugins/panko.rb +63 -0
- data/lib/typelizer/templates/comment.ts.erb +8 -0
- data/lib/typelizer/templates/index.ts.erb +3 -3
- data/lib/typelizer/templates/inheritance.ts.erb +1 -0
- data/lib/typelizer/templates/interface.ts.erb +19 -25
- data/lib/typelizer/version.rb +1 -1
- data/lib/typelizer.rb +1 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 067c0e093a70b8c8273e7504004a687c08272a536367958662e9d7c2fe293151
|
4
|
+
data.tar.gz: 6dc5ef91af5f50ead351f90ee6cf8026360f1f605d06df5a30e20a9633ec168b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b518818c82709eea2ef5461272c929189d0fa59f53aa3f1cb6309e538ffe586b0bd2117cd520a165def41221f9f05528caf934842584f840f64370ce035488a9
|
7
|
+
data.tar.gz: c89f29ad82e7fa44f3118385ccbd8a6ffb5fde9bbe1d3e400994704fdb8a709ccb9b22f029332cd36da6bdc3c8b190b5c0cf1c9492fa5e11cda4ad7d082c8898
|
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,55 @@ and this project adheres to [Semantic Versioning].
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
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
|
+
|
23
|
+
## [0.4.0] - 2025-05-03
|
24
|
+
|
25
|
+
### Added
|
26
|
+
|
27
|
+
- Support for `panko_serializer` gem ([@PedroAugustoRamalhoDuarte], [@skryukov])
|
28
|
+
- Mark `has_one` and `belongs_to` association as nullable. ([@skryukov])
|
29
|
+
|
30
|
+
By default, `has_one` associations are marked as nullable in TypeScript interfaces.
|
31
|
+
`belongs_to` associations are marked as nullable if the database column is nullable.
|
32
|
+
Use the new `config.associations_strategy = :active_record` configuration option to mark associations as nullable based on the `required`/`optional` options.
|
33
|
+
You can also use the type hint `typelize latest_post: {nullable: false}` in the serializer to override the defaults.
|
34
|
+
|
35
|
+
- Support inherited typelization. ([@skryukov])
|
36
|
+
|
37
|
+
Set `config.inheritance_strategy = :inheritance` to make Typelizer respect the inheritance hierarchy of serializers:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
class AdminSerializer < UserSerializer
|
41
|
+
attributes :admin_level
|
42
|
+
end
|
43
|
+
```
|
44
|
+
|
45
|
+
```typescript
|
46
|
+
// app/javascript/types/serializers/Admin.ts
|
47
|
+
import { User } from "@/types";
|
48
|
+
|
49
|
+
export type Admin = User & {
|
50
|
+
admin_level: number;
|
51
|
+
}
|
52
|
+
```
|
53
|
+
|
54
|
+
### Fixed
|
55
|
+
|
56
|
+
- Alba: always use strings for keys in properties. ([@skryukov])
|
57
|
+
This change will fire update of all hashes for Alba serializers, but it's necessary to support inheritance strategy.
|
58
|
+
|
10
59
|
## [0.3.0] - 2025-02-28
|
11
60
|
|
12
61
|
### Added
|
@@ -112,11 +161,16 @@ and this project adheres to [Semantic Versioning].
|
|
112
161
|
|
113
162
|
[@davidrunger]: https://github.com/davidrunger
|
114
163
|
[@Envek]: https://github.com/Envek
|
164
|
+
[@kristinemcbride]: https://github.com/kristinemcbride
|
165
|
+
[@nkriege]: https://github.com/nkriege
|
166
|
+
[@NOX73]: https://github.com/NOX73
|
115
167
|
[@okuramasafumi]: https://github.com/okuramasafumi
|
116
168
|
[@patvice]: https://github.com/patvice
|
117
169
|
[@skryukov]: https://github.com/skryukov
|
118
170
|
|
119
|
-
[Unreleased]: https://github.com/skryukov/typelizer/compare/v0.
|
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
|
173
|
+
[0.4.0]: https://github.com/skryukov/typelizer/compare/v0.3.0...v0.4.0
|
120
174
|
[0.3.0]: https://github.com/skryukov/typelizer/compare/v0.2.0...v0.3.0
|
121
175
|
[0.2.0]: https://github.com/skryukov/typelizer/compare/v0.1.5...v0.2.0
|
122
176
|
[0.1.5]: https://github.com/skryukov/typelizer/compare/v0.1.4...v0.1.5
|
data/README.md
CHANGED
@@ -29,7 +29,7 @@ Typelizer is a Ruby gem that automatically generates TypeScript interfaces from
|
|
29
29
|
## Features
|
30
30
|
|
31
31
|
- Automatic TypeScript interface generation
|
32
|
-
- Support for multiple serializer libraries (`Alba`, `ActiveModel::Serializer`, `Oj::Serializer`)
|
32
|
+
- Support for multiple serializer libraries (`Alba`, `ActiveModel::Serializer`, `Oj::Serializer`, `Panko::Serializer`)
|
33
33
|
- File watching and automatic regeneration in development
|
34
34
|
|
35
35
|
## Installation
|
@@ -50,6 +50,10 @@ Include the Typelizer DSL in your serializers:
|
|
50
50
|
class ApplicationResource
|
51
51
|
include Alba::Resource
|
52
52
|
include Typelizer::DSL
|
53
|
+
|
54
|
+
# For Alba, we recommend using the `helper` method instead of `include`.
|
55
|
+
# See the documentation: https://github.com/okuramasafumi/alba/blob/main/README.md#helper
|
56
|
+
# helper Typelizer::DSL
|
53
57
|
end
|
54
58
|
|
55
59
|
class PostResource < ApplicationResource
|
@@ -252,6 +256,16 @@ Typelizer.configure do |config|
|
|
252
256
|
# Strategy for handling null values (:nullable, :optional, or :nullable_and_optional)
|
253
257
|
config.null_strategy = :nullable
|
254
258
|
|
259
|
+
# Strategy for handling serializer inheritance (:none, :inheritance)
|
260
|
+
# :none - lists all attributes of the serializer in the type
|
261
|
+
# :inheritance - extends the type from the parent serializer
|
262
|
+
config.inheritance_strategy = :none
|
263
|
+
|
264
|
+
# Strategy for handling `has_one` and `belongs_to` associations nullability (:database, :active_record)
|
265
|
+
# :database - uses the database column nullability
|
266
|
+
# :active_record - uses the `required` / `optional` association options
|
267
|
+
config.associations_strategy = :database
|
268
|
+
|
255
269
|
# Directory where TypeScript interfaces will be generated
|
256
270
|
config.output_dir = Rails.root.join("app/javascript/types/serializers")
|
257
271
|
|
@@ -267,6 +281,9 @@ Typelizer.configure do |config|
|
|
267
281
|
# Will change imports and exports of types from default to support this syntax option
|
268
282
|
config.verbatim_module_syntax = false
|
269
283
|
|
284
|
+
# Use double quotes in generated TypeScript interfaces (default: false)
|
285
|
+
config.prefer_double_quotes = false
|
286
|
+
|
270
287
|
# Support comments in generated TypeScript interfaces (default: false)
|
271
288
|
# Will add comments to the generated interfaces
|
272
289
|
config.comments = false
|
data/lib/typelizer/config.rb
CHANGED
@@ -25,7 +25,10 @@ module Typelizer
|
|
25
25
|
:types_import_path,
|
26
26
|
:types_global,
|
27
27
|
:verbatim_module_syntax,
|
28
|
+
:inheritance_strategy,
|
29
|
+
:associations_strategy,
|
28
30
|
:comments,
|
31
|
+
:prefer_double_quotes,
|
29
32
|
keyword_init: true
|
30
33
|
) do
|
31
34
|
class << self
|
@@ -47,7 +50,10 @@ module Typelizer
|
|
47
50
|
|
48
51
|
type_mapping: TYPE_MAPPING,
|
49
52
|
null_strategy: :nullable,
|
53
|
+
inheritance_strategy: :none,
|
54
|
+
associations_strategy: :database,
|
50
55
|
comments: false,
|
56
|
+
prefer_double_quotes: false,
|
51
57
|
|
52
58
|
output_dir: js_root.join("types/serializers"),
|
53
59
|
|
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
@@ -17,7 +17,7 @@ module Typelizer
|
|
17
17
|
|
18
18
|
def name
|
19
19
|
if inline?
|
20
|
-
Renderer.
|
20
|
+
Renderer.call("inline_type.ts.erb", properties: properties).strip
|
21
21
|
else
|
22
22
|
config.serializer_name_mapper.call(serializer).tr_s(":", "")
|
23
23
|
end
|
@@ -53,20 +53,46 @@ module Typelizer
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
+
def overwritten_properties
|
57
|
+
return [] unless parent_interface
|
58
|
+
|
59
|
+
@overwritten_properties ||= parent_interface.properties - properties
|
60
|
+
end
|
61
|
+
|
62
|
+
def own_properties
|
63
|
+
@own_properties ||= properties - (parent_interface&.properties || [])
|
64
|
+
end
|
65
|
+
|
66
|
+
def properties_to_print
|
67
|
+
parent_interface ? own_properties : properties
|
68
|
+
end
|
69
|
+
|
70
|
+
def parent_interface
|
71
|
+
return if config.inheritance_strategy == :none
|
72
|
+
return unless serializer.superclass.respond_to?(:typelizer_interface)
|
73
|
+
|
74
|
+
interface = serializer.superclass.typelizer_interface
|
75
|
+
return if interface.empty?
|
76
|
+
|
77
|
+
interface
|
78
|
+
end
|
79
|
+
|
56
80
|
def imports
|
57
|
-
|
58
|
-
.
|
59
|
-
|
81
|
+
@imports ||= begin
|
82
|
+
association_serializers, attribute_types = properties_to_print.filter_map(&:type)
|
83
|
+
.uniq
|
84
|
+
.partition { |type| type.is_a?(Interface) }
|
60
85
|
|
61
|
-
|
62
|
-
|
86
|
+
serializer_types = association_serializers
|
87
|
+
.filter_map { |interface| interface.name if interface.name != name && !interface.inline? }
|
63
88
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
89
|
+
custom_type_imports = attribute_types
|
90
|
+
.flat_map { |type| extract_typescript_types(type.to_s) }
|
91
|
+
.uniq
|
92
|
+
.reject { |type| global_type?(type) }
|
68
93
|
|
69
|
-
|
94
|
+
(custom_type_imports + serializer_types + Array(parent_interface&.name)).uniq - Array(self_type_name)
|
95
|
+
end
|
70
96
|
end
|
71
97
|
|
72
98
|
def inspect
|
@@ -74,7 +100,11 @@ module Typelizer
|
|
74
100
|
end
|
75
101
|
|
76
102
|
def fingerprint
|
77
|
-
"<#{self.class.name} #{name} properties=[#{
|
103
|
+
"<#{self.class.name} #{name} properties=[#{properties_to_print.map(&:fingerprint).join(", ")}]>"
|
104
|
+
end
|
105
|
+
|
106
|
+
def quote(str)
|
107
|
+
config.prefer_double_quotes ? "\"#{str}\"" : "'#{str}'"
|
78
108
|
end
|
79
109
|
|
80
110
|
private
|
@@ -9,6 +9,30 @@ module Typelizer
|
|
9
9
|
attr_reader :model_class, :config
|
10
10
|
|
11
11
|
def infer_types(prop)
|
12
|
+
if (association = model_class&.reflect_on_association(prop.column_name.to_sym))
|
13
|
+
case association.macro
|
14
|
+
when :belongs_to
|
15
|
+
foreign_key = association.foreign_key
|
16
|
+
column = model_class&.columns_hash&.dig(foreign_key.to_s)
|
17
|
+
if config.associations_strategy == :database
|
18
|
+
prop.nullable = column.null if column
|
19
|
+
elsif config.associations_strategy == :active_record
|
20
|
+
prop.nullable = association.options[:optional] === true || association.options[:required] === false
|
21
|
+
else
|
22
|
+
raise "Unknown associations strategy: #{config.associations_strategy}"
|
23
|
+
end
|
24
|
+
when :has_one
|
25
|
+
if config.associations_strategy == :database
|
26
|
+
prop.nullable = true
|
27
|
+
elsif config.associations_strategy == :active_record
|
28
|
+
prop.nullable = !association.options[:required]
|
29
|
+
else
|
30
|
+
raise "Unknown associations strategy: #{config.associations_strategy}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
return prop
|
34
|
+
end
|
35
|
+
|
12
36
|
column = model_class&.columns_hash&.dig(prop.column_name.to_s)
|
13
37
|
return prop unless column
|
14
38
|
|
data/lib/typelizer/property.rb
CHANGED
@@ -9,6 +9,12 @@ module Typelizer
|
|
9
9
|
"<#{self.class.name} #{props}>"
|
10
10
|
end
|
11
11
|
|
12
|
+
def eql?(other)
|
13
|
+
return false unless other.is_a?(self.class)
|
14
|
+
|
15
|
+
fingerprint == other.fingerprint
|
16
|
+
end
|
17
|
+
|
12
18
|
def to_s
|
13
19
|
type_str = type_name
|
14
20
|
type_str = "Array<#{type_str}>" if multi
|
@@ -18,8 +24,10 @@ module Typelizer
|
|
18
24
|
end
|
19
25
|
|
20
26
|
def fingerprint
|
21
|
-
props = to_h
|
22
|
-
|
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(" ")}>"
|
23
31
|
end
|
24
32
|
|
25
33
|
private
|
data/lib/typelizer/renderer.rb
CHANGED
@@ -4,6 +4,10 @@ require "erb"
|
|
4
4
|
|
5
5
|
module Typelizer
|
6
6
|
class Renderer
|
7
|
+
def self.call(template, **context)
|
8
|
+
new(template).call(**context)
|
9
|
+
end
|
10
|
+
|
7
11
|
def initialize(template)
|
8
12
|
@erb = ERB.new(File.read(File.join(File.dirname(__FILE__), "templates/#{template}")), trim_mode: "-")
|
9
13
|
end
|
@@ -24,5 +28,9 @@ module Typelizer
|
|
24
28
|
spaces = " " * multiplier
|
25
29
|
content.to_s.each_line.map { |line| line.blank? ? line : "#{spaces}#{line}" }.join
|
26
30
|
end
|
31
|
+
|
32
|
+
def render(template, **context)
|
33
|
+
Renderer.call(template, **context)
|
34
|
+
end
|
27
35
|
end
|
28
36
|
end
|
@@ -13,7 +13,7 @@ module Typelizer
|
|
13
13
|
|
14
14
|
def properties
|
15
15
|
serializer._attributes.map do |name, attr|
|
16
|
-
build_property(name, attr)
|
16
|
+
build_property(name.is_a?(Symbol) ? name.name : name, attr)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -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
|
@@ -13,6 +13,8 @@ module Typelizer
|
|
13
13
|
Alba
|
14
14
|
elsif defined?(ActiveModel::Serializer) && serializer.ancestors.include?(ActiveModel::Serializer)
|
15
15
|
AMS
|
16
|
+
elsif defined?(::Panko::Serializer) && serializer.ancestors.include?(::Panko::Serializer)
|
17
|
+
Panko
|
16
18
|
else
|
17
19
|
raise "Can't guess serializer plugin for #{serializer}. " \
|
18
20
|
"Please specify it with `config.serializer_plugin`."
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require_relative "base"
|
2
|
+
|
3
|
+
module Typelizer
|
4
|
+
module SerializerPlugins
|
5
|
+
class Panko < Base
|
6
|
+
def methods_to_typelize
|
7
|
+
[:has_many, :has_one, :attributes, :method_added]
|
8
|
+
end
|
9
|
+
|
10
|
+
def properties
|
11
|
+
descriptor = serializer.new.instance_variable_get(:@descriptor)
|
12
|
+
attributes = descriptor.attributes
|
13
|
+
methods_attributes = descriptor.method_fields
|
14
|
+
has_many_associations = descriptor.has_many_associations
|
15
|
+
has_one_associations = descriptor.has_one_associations
|
16
|
+
|
17
|
+
attributes.map do |att|
|
18
|
+
attribute_property(att)
|
19
|
+
end + methods_attributes.map do |att|
|
20
|
+
attribute_property(att)
|
21
|
+
end + has_many_associations.map do |assoc|
|
22
|
+
association_property(assoc, multi: true)
|
23
|
+
end + has_one_associations.map do |assoc|
|
24
|
+
association_property(assoc, multi: false)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def typelize_method_transform(method:, name:, binding:, type:, attrs:)
|
29
|
+
if method == :method_added && binding.local_variable_defined?(:method)
|
30
|
+
name = binding.local_variable_get(:method)
|
31
|
+
end
|
32
|
+
|
33
|
+
super
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def attribute_property(att)
|
39
|
+
Property.new(
|
40
|
+
name: att.alias_name || att.name,
|
41
|
+
optional: false,
|
42
|
+
nullable: false,
|
43
|
+
multi: false,
|
44
|
+
column_name: att.name
|
45
|
+
)
|
46
|
+
end
|
47
|
+
|
48
|
+
def association_property(assoc, multi: false)
|
49
|
+
key = assoc.name_str
|
50
|
+
serializer = assoc.descriptor.type
|
51
|
+
type = serializer ? Interface.new(serializer: serializer) : nil
|
52
|
+
Property.new(
|
53
|
+
name: key,
|
54
|
+
type: type,
|
55
|
+
optional: false,
|
56
|
+
nullable: false,
|
57
|
+
multi: multi,
|
58
|
+
column_name: key
|
59
|
+
)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<%
|
2
|
+
comment = ""
|
3
|
+
comment += property.comment.to_s if interface.config.comments
|
4
|
+
if property.deprecated
|
5
|
+
comment += "\n@deprecated #{property.deprecated.is_a?(String) ? property.deprecated : ''}"
|
6
|
+
end
|
7
|
+
-%>
|
8
|
+
<%= indent("/** #{comment.strip.split("\n").map(&:strip).join("\n * ")} */\n") unless comment.empty? -%>
|
@@ -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 -%>
|
@@ -0,0 +1 @@
|
|
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,34 +1,28 @@
|
|
1
|
-
|
2
|
-
import type {<%= interface.imports.join(", ") %>} from
|
3
|
-
|
1
|
+
<% if interface.imports.any? -%>
|
2
|
+
import type {<%= interface.imports.join(", ") %>} from <%= interface.quote(interface.config.types_import_path) %>
|
3
|
+
<% end -%>
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
type <%= interface.name %><%= "Data" if interface.root_key %> = <%=
|
6
|
+
render("inheritance.ts.erb", interface: interface).strip if interface.parent_interface
|
7
|
+
-%>
|
8
|
+
<% unless interface.parent_interface && interface.properties_to_print.empty? -%>
|
9
|
+
<%= " & " if interface.parent_interface %>{
|
10
|
+
<% interface.properties_to_print.each do |property| -%>
|
11
|
+
<%= render("comment.ts.erb", interface: interface, property: property) -%>
|
8
12
|
<%= indent(property) %>;
|
9
|
-
|
13
|
+
<% end -%>
|
10
14
|
}
|
11
|
-
|
12
|
-
type <%= interface.name %> = {
|
13
|
-
<%= interface.root_key %>: <%= interface.name %>Data;
|
14
|
-
<%- interface.meta_fields&.each do |property| -%>
|
15
|
-
<%= indent(property) %>;
|
16
|
-
<%- end -%>
|
17
|
-
}
|
18
|
-
<%- else -%>
|
15
|
+
<% end %><% if interface.root_key %>
|
19
16
|
type <%= interface.name %> = {
|
20
|
-
|
21
|
-
|
22
|
-
<%- comment += property.comment.to_s if interface.config.comments -%>
|
23
|
-
<%- comment += "\n@deprecated #{property.deprecated.is_a?(String) ? property.deprecated : ''}" if property.deprecated -%>
|
24
|
-
<%= indent("/** #{comment.strip.split("\n").map(&:strip).join("\n * ")} */\n") unless comment.empty? -%>
|
17
|
+
<%= indent(interface.root_key) %>: <%= interface.name %>Data;
|
18
|
+
<% interface.meta_fields&.each do |property| -%>
|
25
19
|
<%= indent(property) %>;
|
26
|
-
|
20
|
+
<% end -%>
|
27
21
|
}
|
28
|
-
|
22
|
+
<% end -%>
|
29
23
|
|
30
|
-
|
24
|
+
<% if interface.config.verbatim_module_syntax -%>
|
31
25
|
export type { <%= interface.name %> };
|
32
|
-
|
26
|
+
<% else -%>
|
33
27
|
export default <%= interface.name %>;
|
34
|
-
|
28
|
+
<% end -%>
|
data/lib/typelizer/version.rb
CHANGED
data/lib/typelizer.rb
CHANGED
@@ -14,6 +14,7 @@ require_relative "typelizer/serializer_plugins/auto"
|
|
14
14
|
require_relative "typelizer/serializer_plugins/oj_serializers"
|
15
15
|
require_relative "typelizer/serializer_plugins/alba"
|
16
16
|
require_relative "typelizer/serializer_plugins/ams"
|
17
|
+
require_relative "typelizer/serializer_plugins/panko"
|
17
18
|
|
18
19
|
require_relative "typelizer/model_plugins/active_record"
|
19
20
|
require_relative "typelizer/model_plugins/poro"
|
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
|
+
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:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: railties
|
@@ -50,8 +50,11 @@ files:
|
|
50
50
|
- lib/typelizer/serializer_plugins/auto.rb
|
51
51
|
- lib/typelizer/serializer_plugins/base.rb
|
52
52
|
- lib/typelizer/serializer_plugins/oj_serializers.rb
|
53
|
+
- lib/typelizer/serializer_plugins/panko.rb
|
54
|
+
- lib/typelizer/templates/comment.ts.erb
|
53
55
|
- lib/typelizer/templates/fingerprint.ts.erb
|
54
56
|
- lib/typelizer/templates/index.ts.erb
|
57
|
+
- lib/typelizer/templates/inheritance.ts.erb
|
55
58
|
- lib/typelizer/templates/inline_type.ts.erb
|
56
59
|
- lib/typelizer/templates/interface.ts.erb
|
57
60
|
- lib/typelizer/version.rb
|
@@ -80,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
83
|
- !ruby/object:Gem::Version
|
81
84
|
version: '0'
|
82
85
|
requirements: []
|
83
|
-
rubygems_version: 3.6.
|
86
|
+
rubygems_version: 3.6.7
|
84
87
|
specification_version: 4
|
85
88
|
summary: A TypeScript type generator for Ruby serializers.
|
86
89
|
test_files: []
|