katachi 0.0.1.2 → 0.0.1.4

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: 7261fd339cbee8210baf5fda5540cae8e3e7a2f887e056bbe279ad8f5b2d56a9
4
- data.tar.gz: bb55f2b4593eca21d7834d15c9a9ee61443a7ac488fb73754b65fd0baf06d050
3
+ metadata.gz: 883bae0ce10ea6f6788e55dd3dd26429da93b6514f3e098f84fef2d77e7c96a5
4
+ data.tar.gz: a944845c4d55b3dc54be12c3e8d0e80879c9ad00194f2e2afed6431e9a09bd3f
5
5
  SHA512:
6
- metadata.gz: a5c8f3e5c9fee2b329c1b005bd5a8473f01206ba7e74dc2035aa934524857faafaea9742dde9fbcb2e2cd1b266e402e3ba92b2433fa3a073ebeae0f6c34afc9b
7
- data.tar.gz: 3adb7701d9a50619fd1a2e974b87e03b4d56f5092495ba5214f74b515fc244b10d92042eecf21b12536f8df859da7388854ddb13300b8470fb7b7abd9991391a
6
+ metadata.gz: 17f01032afb9118fabd8235a8df89a569475fc6175d26d3c64fb857fa57fe4698faa2ee983f85defc5963651bbd4236fb5d00adc259ec38c1d686f96ad749b74
7
+ data.tar.gz: 4857e4aec605a1500cd4cc8f44cacc7c8d71e5313b1e1e8fecaa9f00a043f3ebff15cd25ef1999e65ea73e72ecc213081541bd110c1b3d4aa9c7ad9e34b06084
data/README.md CHANGED
@@ -280,8 +280,7 @@ RESULT
280
280
  - [ ] Shape-to-TypeScript conversion
281
281
  - [ ] Shape-to-Zod conversion
282
282
  - [ ] Shape-to-OpenAPI conversion
283
- - [ ] Recursive shape definitions (e.g. `:$user => {name: String, spouse: Kt.any_of(:$user, nil)}`)
284
- - [ ] `katachi-rspec-api` for testing+documenting APIs in a way inspired [RSwag](https://github.com/rswag/rswag)
283
+ - [ ] `katachi-rspec-api` for testing+documenting APIs in a way inspired by [RSwag](https://github.com/rswag/rswag)
285
284
 
286
285
  ## Installation
287
286
 
@@ -12,7 +12,7 @@ Here's the story of how they led to the design of Katachi's hash comparison:
12
12
  OpenAPI has handled `null` values a few different ways over the years.
13
13
 
14
14
  - OpenAPI 2.0 (Swagger) didn't support `null` values at all, so people used `x-nullable: true`
15
- - OpenAPI 3.0 make this official by supporting `nullable: true`
15
+ - OpenAPI 3.0 made this official by supporting `nullable: true`
16
16
  - OpenAPI 3.1 found a much simpler way by treating `null` as a type: `type: ["string", "null"]`
17
17
 
18
18
  I like the 3.1 approach of treating `null` as just another possible type.
@@ -140,7 +140,7 @@ Another problem with using `Object => Object` for extra keys is that it's means
140
140
 
141
141
  If the comparison threw a `:hash_mismatch` when the user's hash didn't literally have a key-value pair `Object => Object`, that'd ruin that whole feature.
142
142
 
143
- The lazy solution was to just ignore `Object => Object`, but what if users wanted to be a bit stricter about their extra keys?
143
+ The lazy solution was to just ignore `Object => Object`, but what if users want to be a bit stricter about their extra keys?
144
144
 
145
145
  - `Symbol => String` is a normal data structure to enforce.
146
146
  - `:$email => User` is an excellent description for a lookup hash.
@@ -231,12 +231,12 @@ But it makes for an awesome user experience :)
231
231
 
232
232
  ```ruby
233
233
  shape = {
234
- :$guid => {
234
+ :$uuid => {
235
235
  email: :$email,
236
236
  first_name: String,
237
237
  last_name: String,
238
238
  preferred_name: AnyOf[String, nil],
239
- admin_only_information: AnyOf[Symbol => String, :$undefined],
239
+ admin_only_information: AnyOf[{Symbol => String}, :$undefined],
240
240
  Symbol => Object,
241
241
  },
242
242
  }
@@ -18,6 +18,7 @@ module Katachi::Comparator
18
18
  retrieved_shape = Katachi::Shapes[shape]
19
19
  return retrieved_shape.kt_compare(value) if retrieved_shape.respond_to?(:kt_compare)
20
20
  return compare_equalities(value:, shape: retrieved_shape) if retrieved_shape.is_a?(Proc)
21
+ return object_class_universal_match(value:) if retrieved_shape == Object
21
22
 
22
23
  case value
23
24
  when Array then compare_array(value:, shape: retrieved_shape)
@@ -40,4 +41,8 @@ module Katachi::Comparator
40
41
  end
41
42
  Katachi::ComparisonResult.new(value:, shape:, code:)
42
43
  end
44
+
45
+ private_class_method def self.object_class_universal_match(value:)
46
+ Katachi::ComparisonResult.new(value:, shape: Object, code: :object_class_universal_match)
47
+ end
43
48
  end
@@ -9,10 +9,11 @@ class Katachi::ComparisonResult
9
9
  # For example, :match is considered a match, while :mismatch is not.
10
10
  CODES = {
11
11
  # General
12
+ class_mismatch: false,
12
13
  exact_match: true,
13
14
  match: true,
14
15
  mismatch: false,
15
- class_mismatch: false,
16
+ object_class_universal_match: true,
16
17
  # AnyOf
17
18
  any_of_match: true,
18
19
  any_of_mismatch: false,
@@ -3,3 +3,5 @@
3
3
  require_relative "shapes"
4
4
 
5
5
  Katachi::Shapes.add(:$uuid, /\A\h{8}-\h{4}-\h{4}-\h{4}-\h{12}\z/)
6
+ Katachi::Shapes.add(:$guid, /\A\h{8}-\h{4}-\h{4}-\h{4}-\h{12}\z/)
7
+ # TODO: make :$guid reference the :$uuid shape; requires recursive shape resolution
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Katachi
4
- VERSION = "0.0.1.2"
4
+ VERSION = "0.0.1.4"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: katachi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.2
4
+ version: 0.0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Tannas
@@ -17,12 +17,12 @@ description: |
17
17
  Example usage:
18
18
 
19
19
  shape = {
20
- :$guid => {
20
+ :$uuid => {
21
21
  email: :$email,
22
22
  first_name: String,
23
23
  last_name: String,
24
24
  preferred_name: AnyOf[String, nil],
25
- admin_only_information: AnyOf[Symbol => String, :$undefined],
25
+ admin_only_information: AnyOf[{Symbol => String}, :$undefined],
26
26
  Symbol => Object,
27
27
  },
28
28
  }