camille 0.5.14 → 0.5.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -0
- data/Gemfile.lock +5 -5
- data/benchmarks/returning_multiple_values.rb +94 -0
- data/lib/camille/configuration.rb +18 -9
- data/lib/camille/controller.rb +1 -4
- data/lib/camille/endpoint.rb +2 -2
- data/lib/camille/key_converter.rb +19 -0
- data/lib/camille/object_hash.rb +7 -0
- data/lib/camille/pick_and_omit.rb +1 -1
- data/lib/camille/schema.rb +1 -1
- data/lib/camille/schemas.rb +2 -2
- data/lib/camille/types/object.rb +6 -6
- data/lib/camille/version.rb +1 -1
- data/lib/camille.rb +2 -0
- metadata +9 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c64a49ba269a9488e2990dce715d59e21ec603bb09453bc07b48f1b29cf80183
|
4
|
+
data.tar.gz: 482a7672c68154b5ab94c68318b2672f02f76793ad08372570a1b5ec4049e7b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6ba48e7bc89d06d8ad92eb375cac5d02d783fc35c5732215f068630b57918a5b0bfaccc89b76d49983b384fbac31e2bbbe208d14526ea37489864e2cb2cee67
|
7
|
+
data.tar.gz: cb52ae9bdfc4445c098040b576d1e6910da8b699a615bfea339ed2bf24b0b180408d67a53b03a1c6259aadf3bda9f407d25c5fc17a12fbd22fb42c0aa0b20637
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.5.16
|
4
|
+
|
5
|
+
### Fixed
|
6
|
+
|
7
|
+
* Record keys will no longer be case converted
|
8
|
+
|
9
|
+
## 0.5.15
|
10
|
+
|
11
|
+
### Added
|
12
|
+
|
13
|
+
* Added key conversion cache
|
14
|
+
|
15
|
+
### Changed
|
16
|
+
|
17
|
+
* When generating TS, endpoints are now sorted by name
|
18
|
+
|
3
19
|
## 0.5.14
|
4
20
|
|
5
21
|
### Fixed
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
camille (0.5.
|
4
|
+
camille (0.5.15)
|
5
5
|
rails (>= 6.1, < 8)
|
6
6
|
|
7
7
|
GEM
|
@@ -90,20 +90,20 @@ GEM
|
|
90
90
|
net-imap
|
91
91
|
net-pop
|
92
92
|
net-smtp
|
93
|
-
marcel (1.0.
|
93
|
+
marcel (1.0.4)
|
94
94
|
method_source (1.0.0)
|
95
95
|
mini_mime (1.1.5)
|
96
96
|
minitest (5.17.0)
|
97
|
-
net-imap (0.4.
|
97
|
+
net-imap (0.4.16)
|
98
98
|
date
|
99
99
|
net-protocol
|
100
100
|
net-pop (0.1.2)
|
101
101
|
net-protocol
|
102
102
|
net-protocol (0.2.2)
|
103
103
|
timeout
|
104
|
-
net-smtp (0.
|
104
|
+
net-smtp (0.5.0)
|
105
105
|
net-protocol
|
106
|
-
nio4r (2.
|
106
|
+
nio4r (2.7.3)
|
107
107
|
nokogiri (1.14.2-x86_64-linux)
|
108
108
|
racc (~> 1.4)
|
109
109
|
racc (1.6.2)
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require "benchmark/ips"
|
2
|
+
|
3
|
+
def array_object
|
4
|
+
[1, 2, 3]
|
5
|
+
end
|
6
|
+
|
7
|
+
def hash_object
|
8
|
+
{
|
9
|
+
a: 1,
|
10
|
+
b: 2,
|
11
|
+
c: 3
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
class PlainObject
|
16
|
+
attr_reader :a, :b, :c
|
17
|
+
|
18
|
+
def initialize a, b, c
|
19
|
+
@a = a
|
20
|
+
@b = b
|
21
|
+
@c = c
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def plain_object
|
26
|
+
PlainObject.new(1, 2, 3)
|
27
|
+
end
|
28
|
+
|
29
|
+
StructObject = Struct.new(:a, :b, :c)
|
30
|
+
|
31
|
+
def struct_object
|
32
|
+
StructObject.new(1, 2, 3)
|
33
|
+
end
|
34
|
+
|
35
|
+
DataObject = Data.define(:a, :b, :c)
|
36
|
+
|
37
|
+
def data_object
|
38
|
+
DataObject.new(1, 2, 3)
|
39
|
+
end
|
40
|
+
|
41
|
+
Benchmark.ips do |x|
|
42
|
+
x.report("parallel assignment") do
|
43
|
+
a, b, c = array_object
|
44
|
+
end
|
45
|
+
|
46
|
+
x.report("array access") do
|
47
|
+
arr = array_object
|
48
|
+
a = arr[0]
|
49
|
+
b = arr[1]
|
50
|
+
c = arr[2]
|
51
|
+
end
|
52
|
+
|
53
|
+
x.report("hash access") do
|
54
|
+
hsh = hash_object
|
55
|
+
a = hsh[:a]
|
56
|
+
b = hsh[:b]
|
57
|
+
c = hsh[:c]
|
58
|
+
end
|
59
|
+
|
60
|
+
x.report("hash destructuring") do
|
61
|
+
hash_object => {a:, b:, c:}
|
62
|
+
end
|
63
|
+
|
64
|
+
x.report("plain object") do
|
65
|
+
obj = plain_object
|
66
|
+
a = obj.a
|
67
|
+
b = obj.b
|
68
|
+
c = obj.c
|
69
|
+
end
|
70
|
+
|
71
|
+
x.report("struct object") do
|
72
|
+
obj = struct_object
|
73
|
+
a = obj.a
|
74
|
+
b = obj.b
|
75
|
+
c = obj.c
|
76
|
+
end
|
77
|
+
|
78
|
+
x.report("struct object destructuring") do
|
79
|
+
struct_object => {a:, b:, c:}
|
80
|
+
end
|
81
|
+
|
82
|
+
x.report("data object") do
|
83
|
+
obj = data_object
|
84
|
+
a = obj.a
|
85
|
+
b = obj.b
|
86
|
+
c = obj.c
|
87
|
+
end
|
88
|
+
|
89
|
+
x.report("data object destructuring") do
|
90
|
+
data_object => {a:, b:, c:}
|
91
|
+
end
|
92
|
+
|
93
|
+
x.compare!
|
94
|
+
end
|
@@ -2,21 +2,30 @@
|
|
2
2
|
module Camille
|
3
3
|
class Configuration
|
4
4
|
class << self
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
attr_reader :response_key_converter, :params_key_converter
|
6
|
+
attr_accessor :ts_header, :ts_location
|
7
|
+
|
8
|
+
def load_default_configurations
|
9
|
+
self.response_key_converter = lambda do |string|
|
10
|
+
string.camelize(:lower)
|
11
|
+
end
|
8
12
|
|
9
|
-
|
10
|
-
|
13
|
+
self.params_key_converter = lambda do |string|
|
14
|
+
string.underscore
|
15
|
+
end
|
11
16
|
end
|
12
17
|
|
13
|
-
def
|
14
|
-
@
|
18
|
+
def response_key_converter= lambda
|
19
|
+
@response_key_converter = lambda
|
20
|
+
Camille::Type.define_method :convert_response_key, &lambda
|
15
21
|
end
|
16
22
|
|
17
|
-
def
|
18
|
-
@
|
23
|
+
def params_key_converter= lambda
|
24
|
+
@params_key_converter = lambda
|
25
|
+
Camille::Type.define_method :convert_params_key, &lambda
|
19
26
|
end
|
27
|
+
|
28
|
+
Camille::Configuration.load_default_configurations
|
20
29
|
end
|
21
30
|
end
|
22
31
|
end
|
data/lib/camille/controller.rb
CHANGED
@@ -25,9 +25,6 @@ module Camille
|
|
25
25
|
Camille::TypeErrorPrinter.new(error).print(string_io)
|
26
26
|
raise TypeError.new("\nType check failed for response.\n#{string_io.string}")
|
27
27
|
else
|
28
|
-
if transformed.is_a? Hash
|
29
|
-
transformed.deep_transform_keys!{|k| k.to_s.camelize(:lower)}
|
30
|
-
end
|
31
28
|
super(json: transformed)
|
32
29
|
end
|
33
30
|
else
|
@@ -45,7 +42,7 @@ module Camille
|
|
45
42
|
Camille::Loader.check_and_raise_exception
|
46
43
|
if endpoint = camille_endpoint
|
47
44
|
begin
|
48
|
-
params.deep_transform_keys!{|key| key.to_s
|
45
|
+
params.deep_transform_keys!{|key| Camille::Configuration.params_key_converter.call(key.to_s)}
|
49
46
|
result = super
|
50
47
|
# When there's no `render` call, Rails will return status 204
|
51
48
|
if response.status == 204
|
data/lib/camille/endpoint.rb
CHANGED
@@ -16,9 +16,9 @@ module Camille
|
|
16
16
|
raise UnknownResponseError.new("Endpoint lacking a `response` definition.")
|
17
17
|
end
|
18
18
|
if @params_type
|
19
|
-
"#{
|
19
|
+
"#{Camille::Configuration.response_key_converter.call(@name.to_s)}(params: #{@params_type.literal}): Promise<#{@response_type.literal}>"
|
20
20
|
else
|
21
|
-
"#{
|
21
|
+
"#{Camille::Configuration.response_key_converter.call(@name.to_s)}(): Promise<#{@response_type.literal}>"
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Camille
|
2
|
+
class KeyConverter
|
3
|
+
class << self
|
4
|
+
RESPONSE_KEY_CACHE = {}
|
5
|
+
|
6
|
+
def convert_response_key key
|
7
|
+
if in_cache = RESPONSE_KEY_CACHE[key]
|
8
|
+
in_cache
|
9
|
+
else
|
10
|
+
RESPONSE_KEY_CACHE[key] = Camille::Configuration.response_key_converter.call(key.to_s)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def convert_params_key key
|
15
|
+
Camille::Configuration.params_key_converter.call(key)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/camille/schema.rb
CHANGED
data/lib/camille/schemas.rb
CHANGED
@@ -31,13 +31,13 @@ module Camille
|
|
31
31
|
tree.map do |key, value|
|
32
32
|
if value.is_a? ::Hash
|
33
33
|
[
|
34
|
-
Camille::Line.new("#{
|
34
|
+
Camille::Line.new("#{Camille::Configuration.response_key_converter.call(key.to_s)}: {"),
|
35
35
|
tree_literal_lines(value).map(&:do_indent),
|
36
36
|
Camille::Line.new('},')
|
37
37
|
]
|
38
38
|
else
|
39
39
|
value.literal_lines.tap do |lines|
|
40
|
-
lines.first.prepend("#{
|
40
|
+
lines.first.prepend("#{Camille::Configuration.response_key_converter.call(key.to_s)}: ")
|
41
41
|
lines.last.append(',')
|
42
42
|
end
|
43
43
|
end
|
data/lib/camille/types/object.rb
CHANGED
@@ -32,7 +32,7 @@ module Camille
|
|
32
32
|
transformed = transform_and_check_results.map do |key, (error, transformed)|
|
33
33
|
[key, transformed]
|
34
34
|
end.to_h
|
35
|
-
[nil, transformed]
|
35
|
+
[nil, Camille::ObjectHash[transformed]]
|
36
36
|
else
|
37
37
|
[Camille::TypeError.new(**errors.to_h), nil]
|
38
38
|
end
|
@@ -48,7 +48,7 @@ module Camille
|
|
48
48
|
private
|
49
49
|
def normalize_fields fields
|
50
50
|
fields.map do |key, value|
|
51
|
-
|
51
|
+
check_key_conversion_safe key
|
52
52
|
type = Camille::Type.instance(value)
|
53
53
|
if key.end_with?('?')
|
54
54
|
new_key = remove_question_mark(key)
|
@@ -65,13 +65,13 @@ module Camille
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def literal_key key
|
68
|
-
"#{
|
68
|
+
"#{Camille::Configuration.response_key_converter.call(key.to_s)}#{@optional_keys.include?(key) ? '?' : ''}"
|
69
69
|
end
|
70
70
|
|
71
|
-
def
|
71
|
+
def check_key_conversion_safe sym
|
72
72
|
str = sym.to_s
|
73
|
-
if str !=
|
74
|
-
raise ArgumentError.new("Only keys satisfying `key
|
73
|
+
if str != Camille::Configuration.params_key_converter.call(Camille::Configuration.response_key_converter.call(str))
|
74
|
+
raise ArgumentError.new("Only keys satisfying `key == key.to_s.camelize.underscore` can be used.")
|
75
75
|
end
|
76
76
|
end
|
77
77
|
end
|
data/lib/camille/version.rb
CHANGED
data/lib/camille.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require "active_support"
|
4
4
|
|
5
5
|
require_relative "camille/version"
|
6
|
+
require_relative "camille/object_hash"
|
6
7
|
require_relative "camille/basic_type"
|
7
8
|
require_relative "camille/types"
|
8
9
|
require_relative "camille/types/number"
|
@@ -37,6 +38,7 @@ require_relative "camille/loader"
|
|
37
38
|
require_relative "camille/configuration"
|
38
39
|
require_relative "camille/code_generator"
|
39
40
|
require_relative "camille/main_controller"
|
41
|
+
require_relative "camille/key_converter"
|
40
42
|
|
41
43
|
require "rails/generators"
|
42
44
|
require_relative "camille/generators/install_generator"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: camille
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alyssa
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-10-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -43,6 +43,7 @@ files:
|
|
43
43
|
- Gemfile.lock
|
44
44
|
- README.md
|
45
45
|
- Rakefile
|
46
|
+
- benchmarks/returning_multiple_values.rb
|
46
47
|
- bin/console
|
47
48
|
- bin/setup
|
48
49
|
- gemfiles/rails-6.1
|
@@ -62,9 +63,11 @@ files:
|
|
62
63
|
- lib/camille/generators/templates/schema_template.erb
|
63
64
|
- lib/camille/generators/templates/type_template.erb
|
64
65
|
- lib/camille/generators/type_generator.rb
|
66
|
+
- lib/camille/key_converter.rb
|
65
67
|
- lib/camille/line.rb
|
66
68
|
- lib/camille/loader.rb
|
67
69
|
- lib/camille/main_controller.rb
|
70
|
+
- lib/camille/object_hash.rb
|
68
71
|
- lib/camille/pick_and_omit.rb
|
69
72
|
- lib/camille/railtie.rb
|
70
73
|
- lib/camille/schema.rb
|
@@ -98,7 +101,7 @@ licenses:
|
|
98
101
|
metadata:
|
99
102
|
homepage_uri: https://github.com/onyxblade/camille
|
100
103
|
source_code_uri: https://github.com/onyxblade/camille
|
101
|
-
post_install_message:
|
104
|
+
post_install_message:
|
102
105
|
rdoc_options: []
|
103
106
|
require_paths:
|
104
107
|
- lib
|
@@ -113,8 +116,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
116
|
- !ruby/object:Gem::Version
|
114
117
|
version: '0'
|
115
118
|
requirements: []
|
116
|
-
rubygems_version: 3.
|
117
|
-
signing_key:
|
119
|
+
rubygems_version: 3.5.22
|
120
|
+
signing_key:
|
118
121
|
specification_version: 4
|
119
122
|
summary: Typed API schema for Rails with TypeScript codegen
|
120
123
|
test_files: []
|