souls 0.55.5 → 0.56.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e805c18e5e922c303e5adccdd50f1eea290de27488824feddff3379bbb8f2443
4
- data.tar.gz: a620e8a36cae782adfd24bea8e3cd71319333a5e9c64ecdf18d5f91588a4d476
3
+ metadata.gz: 8b11027355d2156abdaa8807eda594fd4ba96fde1fdb0cf546e6f5f1cd34487a
4
+ data.tar.gz: cba26dd0ea25bafe8ecce20ef66a10f1f2ef86f0bfb0b5f6c54594d332c3400c
5
5
  SHA512:
6
- metadata.gz: d185e3ac5e01a418113b6f460097148ecbd5e8524d03838f9a2de50cd4b45751137c9200c7a4dc0019da6211e3b3d86e43768a9c28da47a2d71a450832b1f098
7
- data.tar.gz: 8b9feee800ab2ca6394a495a448650be3e18071a64de9e23c43c41828db77117ac1e4e70a5891fb1560f08e6144221431e73174c9bc5fc7f1a72164e19d6d24e
6
+ metadata.gz: 5bd75f70b0284d5ecab2a2eda7a013557db7578d69caec27dd9296c3649838413bfe011ea573a63fb8ce94cb9469bb7882b37951de7ec18ff84dd87e03de94ca
7
+ data.tar.gz: 61b91ab91c7cd6b277718b3f9f6bba5451d956d386099a941e2f0f9e4632ad69cec3d897804b36fc0ebb9c0a528d6f2008fdc1140d2e3b01bd7d93874f7aba42
data/README.md CHANGED
@@ -84,7 +84,7 @@ And Create Your APP
84
84
 
85
85
  Check your GraphQL PlayGround
86
86
 
87
- (localhost:4000/playground)[localhost:4000/playground]
87
+ [localhost:4000/playground](localhost:4000/playground)
88
88
 
89
89
  ## Gemfile 自動更新アップデート
90
90
 
@@ -4,18 +4,26 @@ module Souls
4
4
  def scaffold(class_name)
5
5
  singularized_class_name = class_name.singularize
6
6
  model(singularized_class_name)
7
+ model_rbs(singularized_class_name)
7
8
  type(singularized_class_name)
9
+ type_rbs(singularized_class_name)
10
+ query(singularized_class_name)
11
+ query_rbs(singularized_class_name)
12
+ mutation(singularized_class_name)
13
+ mutation_rbs(singularized_class_name)
14
+ policy(singularized_class_name)
15
+ policy_rbs(singularized_class_name)
8
16
  edge(singularized_class_name)
17
+ edge_rbs(singularized_class_name)
9
18
  connection(singularized_class_name)
19
+ connection_rbs(singularized_class_name)
10
20
  resolver(singularized_class_name)
21
+ resolver_rbs(singularized_class_name)
11
22
  rspec_factory(singularized_class_name)
12
23
  rspec_model(singularized_class_name)
13
24
  rspec_mutation(singularized_class_name)
14
25
  rspec_query(singularized_class_name)
15
26
  rspec_resolver(singularized_class_name)
16
- query(singularized_class_name)
17
- mutation(singularized_class_name)
18
- policy(singularized_class_name)
19
27
  rspec_policy(singularized_class_name)
20
28
  true
21
29
  rescue Thor::Error => e
@@ -7,7 +7,7 @@ module Souls
7
7
  file_dir = "./sig/api/app/graphql/types/connections/"
8
8
  FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
9
9
  singularized_class_name = class_name.underscore.singularize
10
- file_path = "#{file_dir}#{singularized_class_name}_connection_rbs.rbs"
10
+ file_path = "#{file_dir}#{singularized_class_name}_connection.rbs"
11
11
  File.open(file_path, "w") do |f|
12
12
  f.write(<<~TEXT)
13
13
  module Types
@@ -7,7 +7,7 @@ module Souls
7
7
  file_dir = "./sig/api/app/graphql/types/edges/"
8
8
  FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
9
9
  singularized_class_name = class_name.underscore.singularize
10
- file_path = "#{file_dir}#{singularized_class_name}_edge_rbs.rbs"
10
+ file_path = "#{file_dir}#{singularized_class_name}_edge.rbs"
11
11
  File.open(file_path, "w") do |f|
12
12
  f.write(<<~TEXT)
13
13
  module Types
@@ -1,30 +1,12 @@
1
- require_relative "./model"
2
- require_relative "./model_rbs"
3
- require_relative "./mutation"
4
- require_relative "./mutation_rbs"
5
- require_relative "./policy"
6
- require_relative "./query"
7
- require_relative "./resolver"
8
- require_relative "./rspec_factory"
9
- require_relative "./rspec_model"
10
- require_relative "./rspec_mutation"
11
- require_relative "./rspec_policy"
12
- require_relative "./rspec_query"
13
- require_relative "./rspec_resolver"
14
- require_relative "./type"
15
- require_relative "./edge"
16
- require_relative "./edge_rbs"
17
- require_relative "./connection"
18
- require_relative "./connection_rbs"
19
- require_relative "./application"
20
- require_relative "./manager"
1
+ require_paths = []
2
+ dev_path = "lib/souls/api/generate/*"
3
+ gem_path = "#{Gem.dir}/gems/souls-#{Souls::VERSION}/lib/souls/api/generate/*"
4
+ file_paths = File.exist?("souls.gemspec") ? dev_path : gem_path
5
+ Dir[file_paths].map do |n|
6
+ next if n.include?("index.rb")
21
7
 
22
- # require_paths = []
23
- # Dir["lib/souls/api/generate/*"].map do |n|
24
- # next if n.include?("index.rb")
25
-
26
- # require_paths << n.split("/").last.gsub(".rb", "")
27
- # end
28
- # require_paths.each do |path|
29
- # require_relative "./#{path}"
30
- # end
8
+ require_paths << n.split("/").last.gsub(".rb", "")
9
+ end
10
+ require_paths.each do |path|
11
+ require_relative "./#{path}"
12
+ end
@@ -7,7 +7,7 @@ module Souls
7
7
  file_dir = "./sig/api/app/graphql/types/models/"
8
8
  FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
9
9
  singularized_class_name = class_name.underscore.singularize
10
- file_path = "#{file_dir}#{singularized_class_name}_model_rbs.rbs"
10
+ file_path = "#{file_dir}#{singularized_class_name}_model.rbs"
11
11
  File.open(file_path, "w") do |f|
12
12
  f.write(<<~TEXT)
13
13
  module Types
@@ -18,10 +18,10 @@ module Souls
18
18
  Dir.chdir(Souls.get_mother_path.to_s) do
19
19
  file_dir = "./sig/api/app/graphql/mutations/base/#{class_name}"
20
20
  FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
21
- file_path = "#{file_dir}/create_#{class_name}_rbs.rbs"
21
+ file_path = "#{file_dir}/create_#{class_name}.rbs"
22
22
  raise(Thor::Error, "Mutation RBS already exist! #{file_path}") if File.exist?(file_path)
23
23
 
24
- params = Souls.get_relation_params(class_name: class_name)
24
+ params = Souls.get_relation_params(class_name: class_name, col: "mutation")
25
25
  File.open(file_path, "w") do |f|
26
26
  f.write(<<~TEXT)
27
27
  class Boolean
@@ -93,8 +93,8 @@ module Souls
93
93
  Dir.chdir(Souls.get_mother_path.to_s) do
94
94
  file_dir = "./sig/api/app/graphql/mutations/base/#{class_name}"
95
95
  FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
96
- file_path = "#{file_dir}/update_#{class_name}_rbs.rbs"
97
- params = Souls.get_relation_params(class_name: class_name)
96
+ file_path = "#{file_dir}/update_#{class_name}.rbs"
97
+ params = Souls.get_relation_params(class_name: class_name, col: "mutation")
98
98
  params[:params] << { column_name: "id", type: "string", array: false }
99
99
  File.open(file_path, "w") do |f|
100
100
  f.write(<<~TEXT)
@@ -160,7 +160,7 @@ module Souls
160
160
  Dir.chdir(Souls.get_mother_path.to_s) do
161
161
  file_dir = "./sig/api/app/graphql/mutations/base/#{class_name}"
162
162
  FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
163
- file_path = "#{file_dir}/delete_#{class_name}_rbs.rbs"
163
+ file_path = "#{file_dir}/delete_#{class_name}.rbs"
164
164
  File.open(file_path, "w") do |f|
165
165
  f.write(<<~TEXT)
166
166
  module Mutations
@@ -191,7 +191,7 @@ module Souls
191
191
  Dir.chdir(Souls.get_mother_path.to_s) do
192
192
  file_dir = "./sig/api/app/graphql/mutations/base/#{class_name}"
193
193
  FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
194
- file_path = "#{file_dir}/destroy_delete_#{class_name}_rbs.rbs"
194
+ file_path = "#{file_dir}/destroy_delete_#{class_name}.rbs"
195
195
  File.open(file_path, "w") do |f|
196
196
  f.write(<<~TEXT)
197
197
  module Mutations
@@ -0,0 +1,35 @@
1
+ module Souls
2
+ class Generate < Thor
3
+ desc "policy_rbs [CLASS_NAME]", "Generate Policy RBS"
4
+ def policy_rbs(class_name)
5
+ file_path = ""
6
+ Dir.chdir(Souls.get_mother_path.to_s) do
7
+ file_dir = "./sig/api/app/graphql/types/policies/"
8
+ FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
9
+ singularized_class_name = class_name.underscore.singularize
10
+ file_path = "#{file_dir}#{singularized_class_name}_policy.rbs"
11
+ File.open(file_path, "w") do |f|
12
+ f.write(<<~TEXT)
13
+ class #{singularized_class_name.camelize}Policy
14
+ @user: untyped
15
+
16
+ def show?: -> true
17
+ def index?: -> true
18
+ def create?: -> bool
19
+ def update?: -> bool
20
+ def delete?: -> bool
21
+
22
+ private
23
+ def user_permissions?: -> untyped
24
+ def admin_permissions?: -> untyped
25
+ end
26
+ TEXT
27
+ end
28
+ puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
29
+ end
30
+ file_path
31
+ rescue Thor::Error => e
32
+ raise(Thor::Error, e)
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,67 @@
1
+ module Souls
2
+ class Generate < Thor
3
+ desc "query_rbs [CLASS_NAME]", "Generate GraphQL Query RBS"
4
+ def query_rbs(class_name)
5
+ single_query_rbs(class_name)
6
+ queries_rbs(class_name)
7
+ end
8
+
9
+ private
10
+
11
+ def single_query_rbs(class_name)
12
+ file_path = ""
13
+ Dir.chdir(Souls.get_mother_path.to_s) do
14
+ file_dir = "./sig/api/app/graphql/queries/"
15
+ FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
16
+ singularized_class_name = class_name.underscore.singularize
17
+ file_path = "#{file_dir}#{singularized_class_name}.rbs"
18
+ File.open(file_path, "w") do |f|
19
+ f.write(<<~TEXT)
20
+ module Queries
21
+ class BaseQuery
22
+ end
23
+ class #{singularized_class_name.camelize} < Queries::BaseQuery
24
+ def resolve: ({
25
+ id: String?
26
+ }) -> ( Hash[Symbol, ( String | Integer | bool )] | ::GraphQL::ExecutionError )
27
+
28
+ def self.argument: (*untyped) -> String
29
+ def self.type: (*untyped) -> String
30
+ end
31
+ end
32
+ TEXT
33
+ end
34
+ puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
35
+ end
36
+ file_path
37
+ rescue Thor::Error => e
38
+ raise(Thor::Error, e)
39
+ end
40
+
41
+ def queries_rbs(class_name)
42
+ file_path = ""
43
+ Dir.chdir(Souls.get_mother_path.to_s) do
44
+ file_dir = "./sig/api/app/graphql/queries/"
45
+ FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
46
+ pluralized_class_name = class_name.underscore.pluralize
47
+ file_path = "#{file_dir}#{pluralized_class_name}.rbs"
48
+ File.open(file_path, "w") do |f|
49
+ f.write(<<~TEXT)
50
+ module Queries
51
+ class BaseQuery
52
+ end
53
+ class #{pluralized_class_name.camelize} < Queries::BaseQuery
54
+ def resolve: () -> ( Hash[Symbol, ( String | Integer | bool )] | ::GraphQL::ExecutionError)
55
+ def self.type: (*untyped) -> String
56
+ end
57
+ end
58
+ TEXT
59
+ end
60
+ puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
61
+ end
62
+ file_path
63
+ rescue Thor::Error => e
64
+ raise(Thor::Error, e)
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,67 @@
1
+ module Souls
2
+ class Generate < Thor
3
+ desc "resolver_rbs [CLASS_NAME]", "Generate GraphQL Resolver RBS from schema.rb"
4
+ def resolver_rbs(class_name)
5
+ singularized_class_name = class_name.underscore.singularize
6
+ file_path = ""
7
+ Dir.chdir(Souls.get_mother_path.to_s) do
8
+ file_dir = "./sig/api/app/graphql/resolvers"
9
+ FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
10
+ file_path = "#{file_dir}/#{singularized_class_name}_search.rbs"
11
+ raise(Thor::Error, "Mutation RBS already exist! #{file_path}") if File.exist?(file_path)
12
+
13
+ params = Souls.get_relation_params(class_name: singularized_class_name)
14
+ File.open(file_path, "w") do |f|
15
+ f.write(<<~TEXT)
16
+ class Base
17
+ end
18
+ class #{singularized_class_name.camelize}Search < Base
19
+ def self.scope: () ?{ () -> nil } -> [Hash[Symbol, untyped]]
20
+ def self.type: (*untyped) -> String
21
+ def self.option: (:filter, type: untyped, with: :apply_filter) -> String
22
+ | (:first, type: untyped, with: :apply_first) -> String
23
+ | (:skip, type: untyped, with: :apply_skip) -> String
24
+ def self.description: (String) -> String
25
+ def self.types: (*untyped) -> String
26
+ def decode_global_key: (String value) -> Integer
27
+ def apply_filter: (untyped scope, untyped value) -> untyped
28
+ def normalize_filters: (untyped value, ?Array[untyped] branches) -> Array[untyped]
29
+
30
+ class #{singularized_class_name.camelize}Filter
31
+ String: String
32
+ Boolean: Boolean
33
+ Integer: Integer
34
+ TEXT
35
+ end
36
+ File.open(file_path, "a") do |f|
37
+ params[:params].each_with_index do |param, i|
38
+ type = Souls.rbs_type_check(param[:type])
39
+ type = "[#{type}]" if param[:array]
40
+ rbs_type = Souls.rbs_type_check(param[:type])
41
+ if i.zero?
42
+ f.write(" def self.argument: (:OR, [self], required: false) -> String\n")
43
+ else
44
+ f.write(" | (:#{param[:column_name]}, #{type}, required: false) -> #{rbs_type}\n")
45
+ end
46
+ end
47
+ end
48
+
49
+ File.open(file_path, "a") do |f|
50
+ f.write(<<~TEXT)
51
+ end
52
+ end
53
+ end
54
+ module Types
55
+ class BaseBaseInputObject
56
+ end
57
+ end
58
+ TEXT
59
+ end
60
+ end
61
+ puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
62
+ file_path
63
+ rescue Thor::Error => e
64
+ raise(Thor::Error, e)
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,50 @@
1
+ module Souls
2
+ class Generate < Thor
3
+ desc "type_rbs [CLASS_NAME]", "Generate GraphQL Type RBS from schema.rb"
4
+ def type_rbs(class_name)
5
+ singularized_class_name = class_name.underscore.singularize
6
+ file_path = ""
7
+ Dir.chdir(Souls.get_mother_path.to_s) do
8
+ file_dir = "./sig/api/app/graphql/types"
9
+ FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
10
+ file_path = "#{file_dir}/#{singularized_class_name}_type.rbs"
11
+ raise(Thor::Error, "Type RBS already exist! #{file_path}") if File.exist?(file_path)
12
+
13
+ params = Souls.get_relation_params(class_name: singularized_class_name)
14
+ File.open(file_path, "w") do |f|
15
+ f.write(<<~TEXT)
16
+ module Types
17
+ class #{singularized_class_name.camelize}Type < BaseObject
18
+ def self.implements: (*untyped) -> untyped
19
+ def self.global_id_field: (:id) -> String
20
+ TEXT
21
+ end
22
+ File.open(file_path, "a") do |f|
23
+ params[:params].each_with_index do |param, i|
24
+ type = Souls.rbs_type_check(param[:type])
25
+ type = "[#{type}]" if param[:array]
26
+ rbs_type = Souls.rbs_type_check(param[:type])
27
+ if i.zero?
28
+ f.write(" def self.field: (:#{param[:column_name]}, #{type}, null: false) -> #{rbs_type}\n")
29
+ else
30
+ f.write(" | (:#{param[:column_name]}, #{type}, null: false) -> #{rbs_type}\n")
31
+ end
32
+ end
33
+ end
34
+
35
+ File.open(file_path, "a") do |f|
36
+ f.write(<<~TEXT)
37
+ def self.edge_type: () -> void
38
+ def self.connection_type: () -> void
39
+ end
40
+ end
41
+ TEXT
42
+ end
43
+ end
44
+ puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
45
+ file_path
46
+ rescue Thor::Error => e
47
+ raise(Thor::Error, e)
48
+ end
49
+ end
50
+ end
@@ -111,8 +111,13 @@ module Souls
111
111
  end
112
112
  end
113
113
 
114
- def get_relation_params(class_name: "user")
115
- cols = get_columns_num(class_name: class_name)
114
+ def get_relation_params(class_name: "user", col: "")
115
+ cols =
116
+ if col == "mutation"
117
+ get_columns_num_no_timestamp(class_name: class_name)
118
+ else
119
+ get_columns_num(class_name: class_name)
120
+ end
116
121
  relation_params = cols.select { |col| col[:column_name].match?(/_id$/) }
117
122
  user_check =
118
123
  relation_params.map do |param|
@@ -142,6 +147,29 @@ module Souls
142
147
  cols
143
148
  end
144
149
 
150
+ def get_columns_num_no_timestamp(class_name: "user")
151
+ pluralized_class_name = class_name.pluralize
152
+ file_path = "./db/schema.rb"
153
+ class_check_flag = false
154
+ cols = []
155
+ File.open(file_path, "r") do |f|
156
+ f.each_line.with_index do |line, _i|
157
+ class_check_flag = true if line.include?("create_table") && line.include?(pluralized_class_name)
158
+ if class_check_flag == true && !line.include?("create_table")
159
+ return cols if line.include?("t.index") || line.strip == "end"
160
+
161
+ types = Souls.get_type_and_name(line)
162
+ array = line.include?("array: true")
163
+ cols << { column_name: types[1], type: types[0], array: array } unless %w[
164
+ created_at
165
+ updated_at
166
+ ].include?(types[1])
167
+ end
168
+ end
169
+ end
170
+ cols
171
+ end
172
+
145
173
  def get_create_migration_type(class_name: "user")
146
174
  pluralized_class_name = class_name.pluralize
147
175
  file_path = Dir["db/migrate/*_create_#{pluralized_class_name}.rb"][0]
data/lib/souls/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Souls
2
- VERSION = "0.55.5".freeze
2
+ VERSION = "0.56.0".freeze
3
3
  public_constant :VERSION
4
4
  end
@@ -1 +1 @@
1
- 0.34.5
1
+ 0.35.0
@@ -1 +1 @@
1
- 0.34.5
1
+ 0.35.0
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: souls
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.55.5
4
+ version: 0.56.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - POPPIN-FUMI
@@ -139,8 +139,11 @@ files:
139
139
  - lib/souls/api/generate/mutation.rb
140
140
  - lib/souls/api/generate/mutation_rbs.rb
141
141
  - lib/souls/api/generate/policy.rb
142
+ - lib/souls/api/generate/policy_rbs.rb
142
143
  - lib/souls/api/generate/query.rb
144
+ - lib/souls/api/generate/query_rbs.rb
143
145
  - lib/souls/api/generate/resolver.rb
146
+ - lib/souls/api/generate/resolver_rbs.rb
144
147
  - lib/souls/api/generate/rspec_factory.rb
145
148
  - lib/souls/api/generate/rspec_model.rb
146
149
  - lib/souls/api/generate/rspec_mutation.rb
@@ -148,6 +151,7 @@ files:
148
151
  - lib/souls/api/generate/rspec_query.rb
149
152
  - lib/souls/api/generate/rspec_resolver.rb
150
153
  - lib/souls/api/generate/type.rb
154
+ - lib/souls/api/generate/type_rbs.rb
151
155
  - lib/souls/api/index.rb
152
156
  - lib/souls/api/update/index.rb
153
157
  - lib/souls/api/update/mutation.rb