ts_schema 0.1.12 → 0.1.13
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/MIT-LICENSE +0 -0
- data/README.md +3 -3
- data/Rakefile +0 -0
- data/lib/generators/install_generator.rb +0 -0
- data/lib/generators/templates/ts_schema.rb +13 -0
- data/lib/tasks/ts_schema_tasks.rake +0 -0
- data/lib/ts_schema/configuration.rb +7 -3
- data/lib/ts_schema/conversion_table.yml +0 -0
- data/lib/ts_schema/railtie.rb +0 -0
- data/lib/ts_schema/schema_generator.rb +23 -5
- data/lib/ts_schema/version.rb +1 -1
- data/lib/ts_schema.rb +0 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d6e690832a89b7cbde62be4a27e6dc9374be937df6627bff391db15c2f1e777
|
4
|
+
data.tar.gz: 9a6aec0dd27e0938cdd856ad723dc28898a582de67122b7ed9bc147ed6d335c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7df830e6e1a3543944f9550e57801f16c9ef2121462983c67944814e70f21c47f48b8fe6d5841286c92d1876cee50c8b32bf1533a49ae90f436234ed52723bcd
|
7
|
+
data.tar.gz: 1cc1c840bef030c08afee4480102d6a4cbda128d30c1de01969ad9b03312c9f71f3019c589ea382e23756ba267f0ab939bc839f62c79619381d7535e9be33de7
|
data/MIT-LICENSE
CHANGED
File without changes
|
data/README.md
CHANGED
@@ -16,9 +16,9 @@ rails generate ts_schema:install
|
|
16
16
|
|
17
17
|
## Usage
|
18
18
|
|
19
|
-
All options with their defaults are in the
|
19
|
+
All options with their defaults are in the generated initializer file.
|
20
20
|
|
21
|
-
By default, every migration
|
21
|
+
By default, every migration will auto generate a new schema file, replacing the existing one. You can disable this behavior in the config file.
|
22
22
|
|
23
23
|
You can manually generate the schema file by running:
|
24
24
|
|
@@ -28,7 +28,7 @@ rails ts_schema:generate
|
|
28
28
|
|
29
29
|
## Gotchas
|
30
30
|
|
31
|
-
|
31
|
+
Sometimes ActiveRecord's inflections will alter the class name. For instance, with a class named `Five`; `"Fives".singularize` returns "Fife", which is not the classname. In the case where Rails alters the classname for an association, you must explicitly define it on the association in the model using `class_name`. Example: `has_many :fives, class_name: "Five"`.
|
32
32
|
|
33
33
|
## License
|
34
34
|
|
data/Rakefile
CHANGED
File without changes
|
File without changes
|
@@ -68,6 +68,19 @@ TsSchema.setup do |config|
|
|
68
68
|
# ]
|
69
69
|
|
70
70
|
|
71
|
+
# Ignore certain fields, omitting them from the generated schema: :optional|(string)|false
|
72
|
+
# Key is the name of the field to override options for.
|
73
|
+
# [:optional] will make this an optional field by adding '?' to the defintion (example: password?: string)
|
74
|
+
# [(string)] enter a field name override, for instance rename encrypted_password to password
|
75
|
+
# In that scenario, also specifying passwoord as an optional field will append a ? in the output
|
76
|
+
# [:omit] will omit the field from being output in the schema entirely
|
77
|
+
#
|
78
|
+
# config.field_overrides: {
|
79
|
+
# encrypted_password: :password,
|
80
|
+
# password: :optional,
|
81
|
+
# }
|
82
|
+
|
83
|
+
|
71
84
|
# Namespace for generated types
|
72
85
|
#
|
73
86
|
# config.namespace = :schema
|
File without changes
|
@@ -10,12 +10,16 @@ module TsSchema
|
|
10
10
|
custom_types: {},
|
11
11
|
default_type: :string,
|
12
12
|
include_associated: true,
|
13
|
+
parent_classes: ["ApplicationRecord"],
|
14
|
+
additional_models: [],
|
15
|
+
field_overrides: {
|
16
|
+
"encrypted_password" => :password,
|
17
|
+
"password" => :optional,
|
18
|
+
},
|
13
19
|
namespace: :schema,
|
14
|
-
|
20
|
+
schema_type: :interface,
|
15
21
|
indent: :tab,
|
16
22
|
spaces: 2,
|
17
|
-
parent_classes: ["ApplicationRecord"],
|
18
|
-
additional_models: []
|
19
23
|
}
|
20
24
|
|
21
25
|
attr_accessor(*DEFAULTS.keys)
|
File without changes
|
data/lib/ts_schema/railtie.rb
CHANGED
File without changes
|
@@ -7,6 +7,7 @@ module TsSchema
|
|
7
7
|
|
8
8
|
def initialize(config = nil)
|
9
9
|
@config = config || TsSchema::Configuration.new
|
10
|
+
@config.field_overrides = @config.field_overrides.stringify_keys
|
10
11
|
@models = []
|
11
12
|
|
12
13
|
Rails.application.eager_load!
|
@@ -66,17 +67,34 @@ module TsSchema
|
|
66
67
|
|
67
68
|
def map_column_types(model)
|
68
69
|
model.columns.map { |i|
|
70
|
+
next if @config.field_overrides[i.name.to_s] == :omit
|
71
|
+
|
69
72
|
type = @types[i.type.to_s] || @config.default_type
|
73
|
+
name = map_name(i.name)
|
74
|
+
null = i.null
|
75
|
+
null = true if @config.field_overrides[name]&.to_s == "optional"
|
70
76
|
|
71
|
-
if(enum = model.defined_enums[
|
77
|
+
if(enum = model.defined_enums[name])
|
72
78
|
type = enum.keys.map { |k| "'#{k}'" }.join("|")
|
73
79
|
end
|
74
|
-
|
80
|
+
|
75
81
|
{
|
76
|
-
name: "#{
|
77
|
-
ts_type: "#{type}#{" | null" if
|
82
|
+
name: "#{name}#{"?" if null }",
|
83
|
+
ts_type: "#{type}#{" | null" if null}"
|
78
84
|
}
|
79
|
-
}
|
85
|
+
}.compact
|
86
|
+
end
|
87
|
+
|
88
|
+
def map_name(name)
|
89
|
+
final_name = name.to_s
|
90
|
+
return final_name unless @config.field_overrides[final_name]
|
91
|
+
|
92
|
+
if @config.field_overrides[final_name]&.to_s != "optional"
|
93
|
+
final_name = @config.field_overrides[final_name]&.to_s
|
94
|
+
|
95
|
+
final_name = map_name(final_name) if @config.field_overrides[final_name]
|
96
|
+
end
|
97
|
+
final_name
|
80
98
|
end
|
81
99
|
|
82
100
|
def map_associations(model)
|
data/lib/ts_schema/version.rb
CHANGED
data/lib/ts_schema.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ts_schema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Avram Walden
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-04-
|
11
|
+
date: 2022-04-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -63,7 +63,7 @@ licenses:
|
|
63
63
|
metadata:
|
64
64
|
homepage_uri: https://github.com/aviemet
|
65
65
|
source_code_uri: https://github.com/aviemet/ts_schema
|
66
|
-
post_install_message:
|
66
|
+
post_install_message:
|
67
67
|
rdoc_options: []
|
68
68
|
require_paths:
|
69
69
|
- lib
|
@@ -79,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
79
|
version: '0'
|
80
80
|
requirements: []
|
81
81
|
rubygems_version: 3.2.32
|
82
|
-
signing_key:
|
82
|
+
signing_key:
|
83
83
|
specification_version: 4
|
84
84
|
summary: Generates typescript definitions from ActiveRecord
|
85
85
|
test_files: []
|