kirei 0.5.1 → 0.6.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 150c91695e10d4bc3fefecf38dfaa5511512aea79c265fdbdb39b3fe2ec9ebba
|
4
|
+
data.tar.gz: 38d983a823588c9c12a4db38cc7f2885e02a7bd7e602eba0f0f04c0581d399b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 072cf7863e6f97b5886ffd4cf0e28d65fda67f23a3beebf967bc2bff7e2776923ac6c07ef42708d69440c91cf4978fff63941e8a5ea6d9c377be9e036613e6ab
|
7
|
+
data.tar.gz: d776d2a47e7d44d0b78b1c7142ae708a04c843472912e46fa0ba93be08b5877349aaa3e243d34092f7560463fecb06ed4b45a994e0661780c95dacd98422a5f2
|
@@ -168,12 +168,13 @@ module Cli
|
|
168
168
|
|
169
169
|
models_dir = #{app_name}.root
|
170
170
|
|
171
|
-
Dir.glob("app/models
|
171
|
+
Dir.glob("app/models/**/*.rb").each do |model_file|
|
172
172
|
next if !model_file_name.nil? && model_file == model_file_name
|
173
173
|
|
174
174
|
model_path = File.expand_path(model_file, models_dir)
|
175
|
-
|
176
|
-
|
175
|
+
modules = model_file.gsub("app/models/", "").gsub(".rb", "").split("/").map { |mod| Zeitwerk::Inflector.new.camelize(mod, model_path) }
|
176
|
+
const_name = modules.join("::")
|
177
|
+
model_klass = Object.const_get(const_name)
|
177
178
|
table_name = model_klass.table_name
|
178
179
|
schema = db.schema(table_name)
|
179
180
|
|
@@ -184,8 +185,10 @@ module Cli
|
|
184
185
|
# Remove existing schema info comments if present
|
185
186
|
updated_contents = file_contents.sub(/# == Schema Info\\n(.*?)(\\n#\\n)?\\n(?=\\s*class)/m, "")
|
186
187
|
|
187
|
-
# Insert the new schema comments before the class definition
|
188
|
-
|
188
|
+
# Insert the new schema comments before the module/class definition
|
189
|
+
first_const = modules.first
|
190
|
+
first_module_or_class = modules.count == 1 ? "class #{first_const}" : "module #{first_const}"
|
191
|
+
modified_contents = updated_contents.sub(/(A|\n)(#{first_module_or_class})/m, "\\1#{schema_comments}\n\n\\2")
|
189
192
|
|
190
193
|
File.write(model_path, modified_contents)
|
191
194
|
end
|
data/lib/kirei/config.rb
CHANGED
@@ -34,6 +34,12 @@ module Kirei
|
|
34
34
|
App.raw_db_connection
|
35
35
|
end
|
36
36
|
|
37
|
+
sig { override.params(sql: String, params: T::Array[T.untyped]).returns(T::Array[T::Hash[Symbol, T.untyped]]) }
|
38
|
+
def exec_sql(sql, params)
|
39
|
+
# Splats aren't supported in Sorbet, see: https://sorbet.org/docs/error-reference#7019
|
40
|
+
T.unsafe(db).fetch(sql, *params).all
|
41
|
+
end
|
42
|
+
|
37
43
|
sig do
|
38
44
|
override.params(
|
39
45
|
hash: T::Hash[Symbol, T.untyped],
|
@@ -107,7 +113,6 @@ module Kirei
|
|
107
113
|
col_info.fetch(:db_type).match?(/vector\(\d+\)/)
|
108
114
|
end
|
109
115
|
|
110
|
-
# New method to cast an array to a vector
|
111
116
|
sig { params(value: T.any(T::Array[Numeric], Sequel::SQL::Expression)).returns(Sequel::SQL::Expression) }
|
112
117
|
def cast_to_vector(value)
|
113
118
|
return value if value.is_a?(Sequel::SQL::Expression) || value.is_a?(Sequel::SQL::PlaceholderLiteralString)
|
data/lib/kirei/routing/base.rb
CHANGED
@@ -98,6 +98,8 @@ module Kirei
|
|
98
98
|
headers[header_name] ||= default_value
|
99
99
|
end
|
100
100
|
|
101
|
+
add_cors_headers(headers, env)
|
102
|
+
|
101
103
|
[
|
102
104
|
status,
|
103
105
|
headers,
|
@@ -143,7 +145,6 @@ module Kirei
|
|
143
145
|
|
144
146
|
sig { returns(T::Hash[String, String]) }
|
145
147
|
def default_headers
|
146
|
-
# "Access-Control-Allow-Origin": the user should set that, see comment about "cors" above
|
147
148
|
{
|
148
149
|
# security relevant headers
|
149
150
|
"X-Frame-Options" => "DENY",
|
@@ -159,6 +160,18 @@ module Kirei
|
|
159
160
|
}
|
160
161
|
end
|
161
162
|
|
163
|
+
sig { params(headers: T::Hash[String, String], env: RackEnvType).void }
|
164
|
+
def add_cors_headers(headers, env)
|
165
|
+
origin = T.cast(env.fetch("HTTP_ORIGIN"), String)
|
166
|
+
allowed_origins = Kirei::App.config.allowed_origins
|
167
|
+
return unless allowed_origins.include?(origin)
|
168
|
+
|
169
|
+
headers["Access-Control-Allow-Origin"] = origin
|
170
|
+
headers["Access-Control-Allow-Methods"] = "GET, POST, PUT, PATCH, DELETE, OPTIONS"
|
171
|
+
headers["Access-Control-Allow-Headers"] = "Content-Type, Authorization, Referer"
|
172
|
+
headers["Access-Control-Allow-Credentials"] = "true"
|
173
|
+
end
|
174
|
+
|
162
175
|
sig { params(hooks: NilableHooksType).void }
|
163
176
|
private def run_hooks(hooks)
|
164
177
|
return if hooks.nil? || hooks.empty?
|
data/lib/kirei/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kirei
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ludwig Reinmiedl
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-09-
|
11
|
+
date: 2024-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oj
|