kirei 0.5.1 → 0.6.1
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: 804455ef32d0df5db5ae939d4befba9d21061b9f98b2dc1b4056ebcf989ea5db
|
4
|
+
data.tar.gz: 3038b88a8f99c8ee6e5769b05c952151260bc80b477ea9db88ed26b95a0bf310
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a54ffcae9908f895e22ed264e7efcf80f9c8694c75ad98e583f84589187499713958905f21fb86dc336fc11aadafa2ed296e87c754e123fc2c9da8762dbf42d
|
7
|
+
data.tar.gz: 387656485eb61c0963abcdae0079a7894f28923954c2544731e170795767408881d533b820df7d746dab96b54064c66ce618635e0a0b292fb49fa1a05ca84eb2
|
@@ -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,20 @@ 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", nil), T.nilable(String))
|
166
|
+
return if origin.nil?
|
167
|
+
|
168
|
+
allowed_origins = Kirei::App.config.allowed_origins
|
169
|
+
return unless allowed_origins.include?(origin)
|
170
|
+
|
171
|
+
headers["Access-Control-Allow-Origin"] = origin
|
172
|
+
headers["Access-Control-Allow-Methods"] = "GET, POST, PUT, PATCH, DELETE, OPTIONS"
|
173
|
+
headers["Access-Control-Allow-Headers"] = "Content-Type, Authorization, Referer"
|
174
|
+
headers["Access-Control-Allow-Credentials"] = "true"
|
175
|
+
end
|
176
|
+
|
162
177
|
sig { params(hooks: NilableHooksType).void }
|
163
178
|
private def run_hooks(hooks)
|
164
179
|
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.1
|
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
|