souls 0.55.1 → 0.55.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 73360700bdc37dfbecd749b27fc7130b74ab5e6b09964de3ef3a69b871ca3757
4
- data.tar.gz: 7f541d2b5b3f2585e400870d8f10d9668c690823f06febfc82ecf993cf1b8e94
3
+ metadata.gz: e805c18e5e922c303e5adccdd50f1eea290de27488824feddff3379bbb8f2443
4
+ data.tar.gz: a620e8a36cae782adfd24bea8e3cd71319333a5e9c64ecdf18d5f91588a4d476
5
5
  SHA512:
6
- metadata.gz: f3fb45003722268317046bf1d2888f92f402e27a9320d61ec0466131f281364ce4ffc6408b17b9abffc1d1fb46e923193dfd6f3753137e8b30bb51dea632e809
7
- data.tar.gz: 2dbe0bb5b0be9f0430f932d3b83b9cc8708c12bdcfed6d31095c88afa67f18f9f1c0bcfb4c812056f5182de6dbad3546dc48e456f3e7ce52818a080137d5581b
6
+ metadata.gz: d185e3ac5e01a418113b6f460097148ecbd5e8524d03838f9a2de50cd4b45751137c9200c7a4dc0019da6211e3b3d86e43768a9c28da47a2d71a450832b1f098
7
+ data.tar.gz: 8b9feee800ab2ca6394a495a448650be3e18071a64de9e23c43c41828db77117ac1e4e70a5891fb1560f08e6144221431e73174c9bc5fc7f1a72164e19d6d24e
data/exe/souls CHANGED
@@ -3,18 +3,7 @@ require "souls"
3
3
  require "thor"
4
4
  begin
5
5
  souls_command = ARGV[0]
6
- require("./config/souls") unless [
7
- "new",
8
- "docker",
9
- "-v",
10
- "deploy",
11
- "help",
12
- "api",
13
- "create",
14
- "worker",
15
- "",
16
- nil
17
- ].include?(souls_command)
6
+ require("./config/souls") unless ["new", "docker", "-v", "help", "", nil].include?(souls_command)
18
7
  rescue StandardError
19
8
  raise(StandardError, "No confif! Please make `./config/souls.rb` File!")
20
9
  end
@@ -1,19 +1,24 @@
1
1
  module Souls
2
2
  class Generate < Thor
3
- desc "connection [CLASS_NAME]", "Generate GraphQL Connection from schema.rb"
4
- def connection(class_name)
5
- file_dir = "./app/graphql/types/connections/"
6
- FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
7
- singularized_class_name = class_name.underscore.singularize
8
- file_path = "./app/graphql/types/connections/#{singularized_class_name}_connection.rb"
9
- File.open(file_path, "w") do |f|
10
- f.write(<<~TEXT)
11
- class Types::#{singularized_class_name.camelize}Connection < Types::BaseConnection
12
- edge_type(Types::#{singularized_class_name.camelize}Edge)
13
- end
14
- TEXT
3
+ desc "connection_rbs [CLASS_NAME]", "Generate GraphQL Connection RBS from schema.rb"
4
+ def connection_rbs(class_name)
5
+ file_path = ""
6
+ Dir.chdir(Souls.get_mother_path.to_s) do
7
+ file_dir = "./sig/api/app/graphql/types/connections/"
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}_connection_rbs.rbs"
11
+ File.open(file_path, "w") do |f|
12
+ f.write(<<~TEXT)
13
+ module Types
14
+ class #{singularized_class_name.camelize}Connection < Types::BaseConnection
15
+ def edge_type: (*untyped) -> untyped
16
+ end
17
+ end
18
+ TEXT
19
+ end
20
+ puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
15
21
  end
16
- puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
17
22
  file_path
18
23
  rescue Thor::Error => e
19
24
  raise(Thor::Error, e)
@@ -0,0 +1,30 @@
1
+ module Souls
2
+ class Generate < Thor
3
+ desc "edge_rbs [CLASS_NAME]", "Generate GraphQL Edge RBS from schema.rb"
4
+ def edge_rbs(class_name)
5
+ file_path = ""
6
+ Dir.chdir(Souls.get_mother_path.to_s) do
7
+ file_dir = "./sig/api/app/graphql/types/edges/"
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}_edge_rbs.rbs"
11
+ File.open(file_path, "w") do |f|
12
+ f.write(<<~TEXT)
13
+ module Types
14
+ class #{singularized_class_name.camelize}Edge < BaseObject
15
+ def self.implements: (*untyped) -> untyped
16
+ def self.global_id_field: (*untyped) -> untyped
17
+ def self.field: (*untyped) -> untyped
18
+ def self.connection_type: ()-> untyped
19
+ end
20
+ end
21
+ TEXT
22
+ end
23
+ puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
24
+ end
25
+ file_path
26
+ rescue Thor::Error => e
27
+ raise(Thor::Error, e)
28
+ end
29
+ end
30
+ end
@@ -1,5 +1,7 @@
1
1
  require_relative "./model"
2
+ require_relative "./model_rbs"
2
3
  require_relative "./mutation"
4
+ require_relative "./mutation_rbs"
3
5
  require_relative "./policy"
4
6
  require_relative "./query"
5
7
  require_relative "./resolver"
@@ -11,7 +13,9 @@ require_relative "./rspec_query"
11
13
  require_relative "./rspec_resolver"
12
14
  require_relative "./type"
13
15
  require_relative "./edge"
16
+ require_relative "./edge_rbs"
14
17
  require_relative "./connection"
18
+ require_relative "./connection_rbs"
15
19
  require_relative "./application"
16
20
  require_relative "./manager"
17
21
 
@@ -0,0 +1,26 @@
1
+ module Souls
2
+ class Generate < Thor
3
+ desc "model_rbs [CLASS_NAME]", "Generate GraphQL Model RBS from schema.rb"
4
+ def model_rbs(class_name)
5
+ file_path = ""
6
+ Dir.chdir(Souls.get_mother_path.to_s) do
7
+ file_dir = "./sig/api/app/graphql/types/models/"
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}_model_rbs.rbs"
11
+ File.open(file_path, "w") do |f|
12
+ f.write(<<~TEXT)
13
+ module Types
14
+ class #{singularized_class_name.camelize} < ActiveRecord::Base
15
+ end
16
+ end
17
+ TEXT
18
+ end
19
+ puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
20
+ end
21
+ file_path
22
+ rescue Thor::Error => e
23
+ raise(Thor::Error, e)
24
+ end
25
+ end
26
+ end
@@ -56,7 +56,8 @@ module Souls
56
56
  new_line.write(<<-TEXT)
57
57
 
58
58
  def resolve args
59
- args[:user_id] = context[:user].id
59
+ params = args.dup
60
+ params[:user_id] = context[:user][:id]
60
61
  TEXT
61
62
  else
62
63
  new_line.write(<<-TEXT)
@@ -150,14 +151,15 @@ module Souls
150
151
  new_line.write(<<-TEXT)
151
152
 
152
153
  def resolve args
153
- args[:user_id] = context[:user].id
154
- _, args[:id] = SoulsApiSchema.from_global_id(args[:id])
154
+ params = args.dup
155
+ params[:user_id] = context[:user][:id]
156
+ _, params[:id] = SoulsApiSchema.from_global_id(args[:id])
155
157
  TEXT
156
158
  else
157
159
  new_line.write(<<-TEXT)
158
160
 
159
161
  def resolve args
160
- _, args[:id] = SoulsApiSchema.from_global_id(args[:id])
162
+ _, params[:id] = SoulsApiSchema.from_global_id(args[:id])
161
163
  TEXT
162
164
  end
163
165
  break
@@ -190,7 +192,7 @@ module Souls
190
192
  file_path = "./app/graphql/mutations/base/#{class_name}/update_#{class_name}.rb"
191
193
  relation_params.each do |params_name|
192
194
  File.open(file_path, "a") do |new_line|
193
- new_line.write(" _, args[:#{params_name}] = SoulsApiSchema.from_global_id(args[:#{params_name}])\n")
195
+ new_line.write(" _, params[:#{params_name}] = SoulsApiSchema.from_global_id(args[:#{params_name}])\n")
194
196
  end
195
197
  end
196
198
  true
@@ -200,9 +202,9 @@ module Souls
200
202
  file_path = "./app/graphql/mutations/base/#{class_name}/update_#{class_name}.rb"
201
203
  File.open(file_path, "a") do |new_line|
202
204
  new_line.write(<<~TEXT)
203
- #{class_name} = ::#{class_name.camelize}.find args[:id]
204
- #{class_name}.update args
205
- { #{class_name}_edge: { node: ::#{class_name.camelize}.find(args[:id]) } }
205
+ #{class_name} = ::#{class_name.camelize}.find params[:id]
206
+ #{class_name}.update params
207
+ { #{class_name}_edge: { node: ::#{class_name.camelize}.find(params[:id]) } }
206
208
  rescue StandardError => error
207
209
  GraphQL::ExecutionError.new(error.message)
208
210
  end
@@ -0,0 +1,220 @@
1
+ module Souls
2
+ class Generate < Thor
3
+ desc "mutation_rbs [CLASS_NAME]", "Generate GraphQL Mutation RBS from schema.rb"
4
+ def mutation_rbs(class_name)
5
+ singularized_class_name = class_name.underscore.singularize
6
+ create_rbs_mutation(class_name: singularized_class_name)
7
+ update_rbs_mutation(class_name: singularized_class_name)
8
+ delete_rbs_mutation(class_name: singularized_class_name)
9
+ destroy_delete_rbs_mutation(class_name: singularized_class_name)
10
+ rescue Thor::Error => e
11
+ raise(Thor::Error, e)
12
+ end
13
+
14
+ private
15
+
16
+ def create_rbs_mutation(class_name: "user")
17
+ file_path = ""
18
+ Dir.chdir(Souls.get_mother_path.to_s) do
19
+ file_dir = "./sig/api/app/graphql/mutations/base/#{class_name}"
20
+ FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
21
+ file_path = "#{file_dir}/create_#{class_name}_rbs.rbs"
22
+ raise(Thor::Error, "Mutation RBS already exist! #{file_path}") if File.exist?(file_path)
23
+
24
+ params = Souls.get_relation_params(class_name: class_name)
25
+ File.open(file_path, "w") do |f|
26
+ f.write(<<~TEXT)
27
+ class Boolean
28
+ end
29
+ module Mutations
30
+ module Base
31
+ module #{class_name.camelize}
32
+ class Create#{class_name.camelize} < BaseMutation
33
+ String: String
34
+ Boolean: Boolean
35
+ Integer: Integer
36
+ def resolve: ({
37
+ TEXT
38
+ end
39
+ File.open(file_path, "a") do |f|
40
+ params[:params].each_with_index do |param, i|
41
+ type = Souls.rbs_type_check(param[:type])
42
+ type = "[#{type}]" if param[:array]
43
+ if i == params[:params].size - 1
44
+ f.write(" #{param[:column_name]}: #{type}?\n")
45
+ else
46
+ f.write(" #{param[:column_name]}: #{type}?,\n")
47
+ end
48
+ end
49
+ end
50
+ # rubocop:disable Layout/LineLength
51
+ File.open(file_path, "a") do |f|
52
+ f.write(" }) -> ({ :#{class_name}_edge => { :node => String } } | ::GraphQL::ExecutionError )\n\n")
53
+ end
54
+ # rubocop:enable Layout/LineLength
55
+
56
+ File.open(file_path, "a") do |f|
57
+ params[:params].each_with_index do |param, i|
58
+ type = Souls.type_check(param[:type])
59
+ rbs_type = Souls.rbs_type_check(param[:type])
60
+ type = "[#{type}]" if param[:array]
61
+ if i.zero?
62
+ f.write(" def self.argument: (:#{param[:column_name]}, #{type}, required: false ) -> #{rbs_type}\n")
63
+ else
64
+ f.write(" | (:#{param[:column_name]}, #{type}, required: false ) -> #{rbs_type}\n")
65
+ end
66
+ end
67
+ end
68
+
69
+ File.open(file_path, "a") do |f|
70
+ f.write(<<~TEXT)
71
+
72
+ def self.field: (*untyped) -> String
73
+ attr_accessor context: {user:{
74
+ id: Integer,
75
+ username: String,
76
+ email: String
77
+ }}
78
+ end
79
+ end
80
+ end
81
+ end
82
+ TEXT
83
+ end
84
+ end
85
+ puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
86
+ file_path
87
+ rescue Thor::Error => e
88
+ raise(Thor::Error, e)
89
+ end
90
+
91
+ def update_rbs_mutation(class_name: "user")
92
+ file_path = ""
93
+ Dir.chdir(Souls.get_mother_path.to_s) do
94
+ file_dir = "./sig/api/app/graphql/mutations/base/#{class_name}"
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)
98
+ params[:params] << { column_name: "id", type: "string", array: false }
99
+ File.open(file_path, "w") do |f|
100
+ f.write(<<~TEXT)
101
+ module Mutations
102
+ module Base
103
+ module #{class_name.camelize}
104
+ class Update#{class_name.camelize} < BaseMutation
105
+ def resolve: ({
106
+ TEXT
107
+ end
108
+ File.open(file_path, "a") do |f|
109
+ params[:params].each_with_index do |param, i|
110
+ type = Souls.rbs_type_check(param[:type])
111
+ type = "[#{type}]" if param[:array]
112
+ if i == params[:params].size - 1
113
+ f.write(" #{param[:column_name]}: #{type}?\n")
114
+ else
115
+ f.write(" #{param[:column_name]}: #{type}?,\n")
116
+ end
117
+ end
118
+ end
119
+ # rubocop:disable Layout/LineLength
120
+ File.open(file_path, "a") do |f|
121
+ f.write(" }) -> ({ :#{class_name}_edge => { :node => String } } | ::GraphQL::ExecutionError )\n\n")
122
+ end
123
+ # rubocop:enable Layout/LineLength
124
+
125
+ File.open(file_path, "a") do |f|
126
+ params[:params].each_with_index do |param, i|
127
+ type = Souls.type_check(param[:type])
128
+ rbs_type = Souls.rbs_type_check(param[:type])
129
+ type = "[#{type}]" if param[:array]
130
+ if i.zero?
131
+ f.write(" def self.argument: (:#{param[:column_name]}, #{type}, required: false ) -> #{rbs_type}\n")
132
+ else
133
+ f.write(" | (:#{param[:column_name]}, #{type}, required: false ) -> #{rbs_type}\n")
134
+ end
135
+ end
136
+ end
137
+
138
+ File.open(file_path, "a") do |f|
139
+ f.write(<<~TEXT)
140
+
141
+ def self.field: (*untyped) -> String
142
+ attr_accessor context: {user:{
143
+ id: Integer,
144
+ username: String,
145
+ email: String
146
+ }}
147
+ end
148
+ end
149
+ end
150
+ end
151
+ TEXT
152
+ end
153
+ end
154
+ puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
155
+ file_path
156
+ end
157
+
158
+ def delete_rbs_mutation(class_name: "user")
159
+ file_path = ""
160
+ Dir.chdir(Souls.get_mother_path.to_s) do
161
+ file_dir = "./sig/api/app/graphql/mutations/base/#{class_name}"
162
+ FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
163
+ file_path = "#{file_dir}/delete_#{class_name}_rbs.rbs"
164
+ File.open(file_path, "w") do |f|
165
+ f.write(<<~TEXT)
166
+ module Mutations
167
+ module Base
168
+ module #{class_name.camelize}
169
+ class Delete#{class_name.camelize}
170
+ def resolve: ({
171
+ id: String
172
+ }) -> ( Hash[Symbol, untyped] | ::GraphQL::ExecutionError )
173
+ #{' '}
174
+ def self.argument: (*untyped) -> String
175
+ def self.field: (*untyped) -> String
176
+ end
177
+ end
178
+ end
179
+ end
180
+ TEXT
181
+ end
182
+ puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
183
+ end
184
+ file_path
185
+ rescue Thor::Error => e
186
+ raise(Thor::Error, e)
187
+ end
188
+
189
+ def destroy_delete_rbs_mutation(class_name: "user")
190
+ file_path = ""
191
+ Dir.chdir(Souls.get_mother_path.to_s) do
192
+ file_dir = "./sig/api/app/graphql/mutations/base/#{class_name}"
193
+ FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
194
+ file_path = "#{file_dir}/destroy_delete_#{class_name}_rbs.rbs"
195
+ File.open(file_path, "w") do |f|
196
+ f.write(<<~TEXT)
197
+ module Mutations
198
+ module Base
199
+ module #{class_name.camelize}
200
+ class DestroyDelete#{class_name.camelize}
201
+ def resolve: ({
202
+ id: String
203
+ }) -> ( Hash[Symbol, untyped] | ::GraphQL::ExecutionError )
204
+ #{' '}
205
+ def self.argument: (*untyped) -> String
206
+ def self.field: (*untyped) -> String
207
+ end
208
+ end
209
+ end
210
+ end
211
+ TEXT
212
+ end
213
+ puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
214
+ end
215
+ file_path
216
+ rescue Thor::Error => e
217
+ raise(Thor::Error, e)
218
+ end
219
+ end
220
+ end
data/lib/souls/cli.rb CHANGED
@@ -44,15 +44,17 @@ module Souls
44
44
  puts(Souls::VERSION)
45
45
  end
46
46
 
47
- desc "test", "Run (Rspec & steep check & Rubocop)"
47
+ desc "test", "Run Rspec & Rubocop"
48
48
  def test
49
49
  system("rubocop -A")
50
- system("steep check")
51
50
  system("bundle exec rspec")
52
51
  end
53
52
 
54
- desc "test_all", "Run Rspec & Rubocop"
53
+ desc "test_all", "Run (Rspec & steep check & Rubocop)"
55
54
  def test_all
55
+ Dir.chdir(Souls.get_mother_path.to_s) do
56
+ system("steep check")
57
+ end
56
58
  system("rubocop -A")
57
59
  system("bundle exec rspec")
58
60
  end
@@ -21,6 +21,19 @@ module Souls
21
21
  }[type.to_sym]
22
22
  end
23
23
 
24
+ def rbs_type_check(type)
25
+ {
26
+ bigint: "Integer",
27
+ string: "String",
28
+ float: "Float",
29
+ text: "String",
30
+ datetime: "String",
31
+ date: "String",
32
+ boolean: "bool",
33
+ integer: "Integer"
34
+ }[type.to_sym]
35
+ end
36
+
24
37
  def get_type_and_name(line)
25
38
  line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
26
39
  end
@@ -98,13 +111,25 @@ module Souls
98
111
  end
99
112
  end
100
113
 
114
+ def get_relation_params(class_name: "user")
115
+ cols = get_columns_num(class_name: class_name)
116
+ relation_params = cols.select { |col| col[:column_name].match?(/_id$/) }
117
+ user_check =
118
+ relation_params.map do |param|
119
+ param[:column_name] == "user_id"
120
+ end
121
+ user_exist = user_check.include?(true)
122
+ { user_exist: user_exist, params: cols, relation_params: relation_params }
123
+ end
124
+
101
125
  def get_columns_num(class_name: "user")
126
+ pluralized_class_name = class_name.pluralize
102
127
  file_path = "./db/schema.rb"
103
128
  class_check_flag = false
104
129
  cols = []
105
130
  File.open(file_path, "r") do |f|
106
131
  f.each_line.with_index do |line, _i|
107
- class_check_flag = true if line.include?("create_table") && line.include?(class_name)
132
+ class_check_flag = true if line.include?("create_table") && line.include?(pluralized_class_name)
108
133
  if class_check_flag == true && !line.include?("create_table")
109
134
  return cols if line.include?("t.index") || line.strip == "end"
110
135
 
data/lib/souls/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Souls
2
- VERSION = "0.55.1".freeze
2
+ VERSION = "0.55.5".freeze
3
3
  public_constant :VERSION
4
4
  end
@@ -1 +1 @@
1
- 0.34.1
1
+ 0.34.5
@@ -1 +1 @@
1
- 0.34.1
1
+ 0.34.5
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.1
4
+ version: 0.55.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - POPPIN-FUMI
@@ -131,10 +131,13 @@ files:
131
131
  - lib/souls/api/generate/connection.rb
132
132
  - lib/souls/api/generate/connection_rbs.rb
133
133
  - lib/souls/api/generate/edge.rb
134
+ - lib/souls/api/generate/edge_rbs.rb
134
135
  - lib/souls/api/generate/index.rb
135
136
  - lib/souls/api/generate/manager.rb
136
137
  - lib/souls/api/generate/model.rb
138
+ - lib/souls/api/generate/model_rbs.rb
137
139
  - lib/souls/api/generate/mutation.rb
140
+ - lib/souls/api/generate/mutation_rbs.rb
138
141
  - lib/souls/api/generate/policy.rb
139
142
  - lib/souls/api/generate/query.rb
140
143
  - lib/souls/api/generate/resolver.rb