ts_schema 0.1.13 → 0.1.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +0 -0
- data/README.md +42 -0
- data/Rakefile +0 -0
- data/lib/generators/install_generator.rb +0 -0
- data/lib/generators/templates/ts_schema.rb +24 -24
- data/lib/tasks/ts_schema_tasks.rake +0 -0
- data/lib/ts_schema/configuration.rb +0 -0
- data/lib/ts_schema/conversion_table.yml +0 -0
- data/lib/ts_schema/railtie.rb +0 -0
- data/lib/ts_schema/schema_generator.rb +3 -1
- data/lib/ts_schema/version.rb +1 -1
- data/lib/ts_schema.rb +0 -0
- 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: e970a98bd2aea544c74c48dac67799e5b713ef56ab8eaa023662f2901973983a
|
4
|
+
data.tar.gz: f259f07ed9fd61a06bf8b0c777df0a50696472534ba48f43737351a8982b3fb5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30fcd65e0da2df3d5741fe12ed25f84139d3d94b1bc840661a9404105fe5a15e5a0f7a328817283c23592de13ab196d1d31df4398281c6a186d3afcef0d23eb4
|
7
|
+
data.tar.gz: 1a44cc70e7acfb79209f03d2311eb368c1d128832c4e8f586c5ca7f7fa209d5f80641fd8ee57848f6e7b7f9573b1c97e399d372fcb8407b772dd4096b5d1be57
|
data/MIT-LICENSE
CHANGED
File without changes
|
data/README.md
CHANGED
@@ -26,6 +26,48 @@ You can manually generate the schema file by running:
|
|
26
26
|
rails ts_schema:generate
|
27
27
|
```
|
28
28
|
|
29
|
+
### Default type mappings
|
30
|
+
|
31
|
+
|Ruby Type|Typescript Type|
|
32
|
+
|:---|:---|
|
33
|
+
|string|string|
|
34
|
+
|text|string|
|
35
|
+
|integer|number|
|
36
|
+
|enum|number|
|
37
|
+
|bigint|number|
|
38
|
+
|float|number|
|
39
|
+
|decimal|number|
|
40
|
+
|json|Record<string, any>|
|
41
|
+
|jsonb|Record<string, any>|
|
42
|
+
|binary|string|
|
43
|
+
|boolean|boolean|
|
44
|
+
|date|string|
|
45
|
+
|datetime|string|
|
46
|
+
|timestamp|string|
|
47
|
+
|datetime_with_timezone|string|
|
48
|
+
|inet|string|
|
49
|
+
|cidr|string|
|
50
|
+
|macaddr|string|
|
51
|
+
|
52
|
+
### Initializer options
|
53
|
+
|
54
|
+
|Option|Default|Values|Description|
|
55
|
+
|---|---|---|---|
|
56
|
+
|case |`:camel`|`:camel`<br/>`:snake`<br/>`:pascal`|camelCase<br/>snake_case<br/>PascalCase|
|
57
|
+
|output |`Rails.root.join('app', 'assets', 'javascripts', 'schema.d.ts')`|Any path|Path to output generated file|
|
58
|
+
|auto_generate |`true`|`boolean`|Whether to automatically (re)generate the defenitions after running migrations|
|
59
|
+
|custom_types |`{}`|`{ ruby_type: 'typescriptType' }`|Use to add or override type mappings for any type|
|
60
|
+
|default_type |`:string`|Any typescript type|The default output type to use if a ruby type is not included in the type mappings|
|
61
|
+
|include_associated|`true`|`boolean`|Whether to include associated models as fields on the generated interfaces|
|
62
|
+
|parent_classes |`["ApplicationRecord"]`|Array of string names of top level classes|Any class names included in this array will be querried for subclasses to generate types for|
|
63
|
+
|additional_models |`[]`|Array of string names of ActiveRecord models|Add model names which don't inherit from classes included in `parent_classes`, but which should have types generated|
|
64
|
+
|field_overrides |`{ encrypted_password: :password, password: :optional, }`|Hash of field names with the following values:<br/> `:optional`: Makes it an optional field by adding '?' to the defintion (example: password?: string)<br/>`:omit`: Omits the field from being output in the schema entirely<br/>`[string]`: Field name override. Will replace any instance of the hash key with the value. The default values replace `password` with `encrypted_password`|Overwrite, omit, or make optional any field name. Applies to all generated classes|
|
65
|
+
|namespace |`:schema`|string\|symbol|The typescript namespace to contain generated types|
|
66
|
+
|schema_type |`:interface`|`:interface`\|`:type`|Whether to generate typescript definitions as types or interfaces. Interfaces are recommended since they are easier to extend|
|
67
|
+
|indent|`:tab`|`:tab`\|`:space`|Indentation using tabs or spaces|
|
68
|
+
|spaces|`2`|number|Number of spaces for indentation if indentation is set to spaces|
|
69
|
+
|
70
|
+
|
29
71
|
## Gotchas
|
30
72
|
|
31
73
|
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"`.
|
data/Rakefile
CHANGED
File without changes
|
File without changes
|
@@ -1,26 +1,5 @@
|
|
1
|
-
# Default type mappings:
|
2
|
-
#
|
3
|
-
# string: string
|
4
|
-
# text: string
|
5
|
-
# integer: number
|
6
|
-
# enum: number
|
7
|
-
# bigint: number
|
8
|
-
# float: number
|
9
|
-
# decimal: number
|
10
|
-
# json: Record<string, any>
|
11
|
-
# jsonb: Record<string, any>
|
12
|
-
# binary: string
|
13
|
-
# boolean: boolean
|
14
|
-
# date: string
|
15
|
-
# datetime: string
|
16
|
-
# timestamp: string
|
17
|
-
# datetime_with_timezone: string
|
18
|
-
# inet: string
|
19
|
-
# cidr: string
|
20
|
-
# macaddr: string
|
21
|
-
|
22
1
|
TsSchema.setup do |config|
|
23
|
-
# Case options: camel|snake|pascal
|
2
|
+
# Case options for field names: camel|snake|pascal
|
24
3
|
#
|
25
4
|
# config.case = :camel
|
26
5
|
|
@@ -35,7 +14,27 @@ TsSchema.setup do |config|
|
|
35
14
|
# config.auto_generate = true
|
36
15
|
|
37
16
|
|
38
|
-
# Add custom type mappings or overrides
|
17
|
+
# Add custom type mappings or overrides (as strings or symbols)
|
18
|
+
#
|
19
|
+
# Default type mappings:
|
20
|
+
# string: string
|
21
|
+
# text: string
|
22
|
+
# integer: number
|
23
|
+
# enum: number
|
24
|
+
# bigint: number
|
25
|
+
# float: number
|
26
|
+
# decimal: number
|
27
|
+
# json: Record<string, any>
|
28
|
+
# jsonb: Record<string, any>
|
29
|
+
# binary: string
|
30
|
+
# boolean: boolean
|
31
|
+
# date: string
|
32
|
+
# datetime: string
|
33
|
+
# timestamp: string
|
34
|
+
# datetime_with_timezone: string
|
35
|
+
# inet: string
|
36
|
+
# cidr: string
|
37
|
+
# macaddr: string
|
39
38
|
#
|
40
39
|
# config.custom_types = {
|
41
40
|
#
|
@@ -70,9 +69,10 @@ TsSchema.setup do |config|
|
|
70
69
|
|
71
70
|
# Ignore certain fields, omitting them from the generated schema: :optional|(string)|false
|
72
71
|
# Key is the name of the field to override options for.
|
72
|
+
#
|
73
73
|
# [:optional] will make this an optional field by adding '?' to the defintion (example: password?: string)
|
74
74
|
# [(string)] enter a field name override, for instance rename encrypted_password to password
|
75
|
-
#
|
75
|
+
# In that scenario, also specifying password as an optional field will append a ? to password
|
76
76
|
# [:omit] will omit the field from being output in the schema entirely
|
77
77
|
#
|
78
78
|
# config.field_overrides: {
|
File without changes
|
File without changes
|
File without changes
|
data/lib/ts_schema/railtie.rb
CHANGED
File without changes
|
@@ -19,6 +19,8 @@ module TsSchema
|
|
19
19
|
m.to_s.constantize
|
20
20
|
end)
|
21
21
|
end
|
22
|
+
@models.sort_by! { |c| c.name }
|
23
|
+
|
22
24
|
@types = @config.types.stringify_keys.merge(@config.custom_types.stringify_keys || {})
|
23
25
|
end
|
24
26
|
|
@@ -34,7 +36,7 @@ module TsSchema
|
|
34
36
|
|
35
37
|
def generate
|
36
38
|
type_template = ""
|
37
|
-
|
39
|
+
|
38
40
|
@models.each do |model|
|
39
41
|
columns = map_column_types(model)
|
40
42
|
columns.concat(map_associations(model)) if @config.include_associated
|
data/lib/ts_schema/version.rb
CHANGED
data/lib/ts_schema.rb
CHANGED
File without changes
|
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.14
|
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-
|
11
|
+
date: 2022-07-09 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: []
|