camille 0.5.11 → 0.5.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -0
- data/Gemfile.lock +1 -1
- data/README.md +11 -0
- data/lib/camille/type.rb +9 -0
- data/lib/camille/type_error.rb +8 -2
- data/lib/camille/types/object.rb +1 -1
- data/lib/camille/types/omit.rb +7 -0
- data/lib/camille/types/pick.rb +7 -0
- data/lib/camille/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d72196c6854c4c1354a55e5560b649753e49e23875a96d903b2d197dbae72581
|
4
|
+
data.tar.gz: 43b711376dfa6e9311245463738d999ffe73abc8fa9c7eb9516100f0f778c018
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 513b2edc45cf95615c6a0d6768a09b7a9ec40fdafb79756694db91b72ab7c614b49140ed6cd7e4cba1a0e8a033e39c5b50aec3ac20d8e5fac25f9ba169f958af
|
7
|
+
data.tar.gz: '077171197c9aaea4b898ebe5157333d72b2f78297ec08b84605cf9da3615543e24af37f21d06d0a501bb1aa077aa21972e77c1f7c28967fff9274702578a22e1'
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,22 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.5.13
|
4
|
+
|
5
|
+
### Fixed
|
6
|
+
|
7
|
+
* Fixed that `Omit` and `Pick` did not preserve optional fields
|
8
|
+
|
9
|
+
## 0.5.12
|
10
|
+
|
11
|
+
### Added
|
12
|
+
|
13
|
+
* Added `.test` to `Camille::Type`
|
14
|
+
* Added error details to `Camille::TypeError#inspect` and `#to_s`
|
15
|
+
|
16
|
+
### Changed
|
17
|
+
|
18
|
+
* Removed `Camille::TypeError#print` since details are now in `#inspect`
|
19
|
+
|
3
20
|
## 0.5.11
|
4
21
|
|
5
22
|
### Changed
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -128,6 +128,17 @@ Each custom type is considered a type alias in TypeScript. And `alias_of` define
|
|
128
128
|
type Product = {id: number, name: string}
|
129
129
|
```
|
130
130
|
|
131
|
+
You can perform a type check on a value using `test`, which might be handy in testing:
|
132
|
+
|
133
|
+
```ruby
|
134
|
+
error = Camille::Types::Product.test(hash)
|
135
|
+
if error.nil?
|
136
|
+
# the hash is accepted by Camille::Types::Product type
|
137
|
+
else
|
138
|
+
p error
|
139
|
+
end
|
140
|
+
```
|
141
|
+
|
131
142
|
### Available syntax for types
|
132
143
|
|
133
144
|
Camille supports most of the type syntax in TypeScript. Below is a list of types that you can use in type and schema definition.
|
data/lib/camille/type.rb
CHANGED
@@ -26,6 +26,15 @@ module Camille
|
|
26
26
|
@underlying.transform_and_check transformed
|
27
27
|
end
|
28
28
|
|
29
|
+
def test value
|
30
|
+
error, _ = transform_and_check value
|
31
|
+
error
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.test value
|
35
|
+
new.test value
|
36
|
+
end
|
37
|
+
|
29
38
|
def self.klass_name
|
30
39
|
name.gsub(/^Camille::Types::/, '')
|
31
40
|
end
|
data/lib/camille/type_error.rb
CHANGED
@@ -18,8 +18,14 @@ module Camille
|
|
18
18
|
!!@message
|
19
19
|
end
|
20
20
|
|
21
|
-
def
|
22
|
-
|
21
|
+
def inspect
|
22
|
+
string_io = StringIO.new
|
23
|
+
Camille::TypeErrorPrinter.new(self).print string_io
|
24
|
+
"#<Camille::TypeError\n#{string_io.string}>"
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_s
|
28
|
+
inspect
|
23
29
|
end
|
24
30
|
end
|
25
31
|
end
|
data/lib/camille/types/object.rb
CHANGED
data/lib/camille/types/omit.rb
CHANGED
@@ -12,6 +12,13 @@ module Camille
|
|
12
12
|
|
13
13
|
def processed_object
|
14
14
|
fields = @target_object.fields.reject{|k, _| @keys.include?(k)}
|
15
|
+
fields.transform_keys! do |k,_|
|
16
|
+
if @target_object.optional_keys.include?(k)
|
17
|
+
"#{k}?".to_sym
|
18
|
+
else
|
19
|
+
k
|
20
|
+
end
|
21
|
+
end
|
15
22
|
Camille::Types::Object.new(fields)
|
16
23
|
end
|
17
24
|
|
data/lib/camille/types/pick.rb
CHANGED
@@ -12,6 +12,13 @@ module Camille
|
|
12
12
|
|
13
13
|
def processed_object
|
14
14
|
fields = @target_object.fields.select{|k, _| @keys.include?(k)}
|
15
|
+
fields.transform_keys! do |k,_|
|
16
|
+
if @target_object.optional_keys.include?(k)
|
17
|
+
"#{k}?".to_sym
|
18
|
+
else
|
19
|
+
k
|
20
|
+
end
|
21
|
+
end
|
15
22
|
Camille::Types::Object.new(fields)
|
16
23
|
end
|
17
24
|
|
data/lib/camille/version.rb
CHANGED
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.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Alyssa
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '8'
|
33
33
|
description: ''
|
34
34
|
email:
|
35
|
-
-
|
35
|
+
- git@alyssa.fm
|
36
36
|
executables: []
|
37
37
|
extensions: []
|
38
38
|
extra_rdoc_files: []
|