domainic-type 0.1.0.alpha.3.0.2 → 0.1.0.alpha.3.1.0

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.
Files changed (29) hide show
  1. checksums.yaml +4 -4
  2. data/lib/domainic/type/behavior/string_behavior/matching_behavior.rb +115 -0
  3. data/lib/domainic/type/behavior/string_behavior.rb +2 -111
  4. data/lib/domainic/type/behavior/uri_behavior.rb +97 -0
  5. data/lib/domainic/type/behavior.rb +21 -1
  6. data/lib/domainic/type/config/registry.yml +15 -0
  7. data/lib/domainic/type/definitions.rb +182 -1
  8. data/lib/domainic/type/types/core/array_type.rb +1 -1
  9. data/lib/domainic/type/types/core/float_type.rb +1 -1
  10. data/lib/domainic/type/types/core/hash_type.rb +1 -1
  11. data/lib/domainic/type/types/core/integer_type.rb +1 -1
  12. data/lib/domainic/type/types/core/string_type.rb +1 -1
  13. data/lib/domainic/type/types/core/symbol_type.rb +1 -1
  14. data/lib/domainic/type/types/identifier/cuid_type.rb +140 -0
  15. data/lib/domainic/type/types/identifier/uuid_type.rb +513 -0
  16. data/lib/domainic/type/types/network/email_address_type.rb +149 -0
  17. data/lib/domainic/type/types/network/hostname_type.rb +107 -0
  18. data/lib/domainic/type/types/network/uri_type.rb +224 -0
  19. data/sig/domainic/type/behavior/string_behavior/matching_behavior.rbs +84 -0
  20. data/sig/domainic/type/behavior/string_behavior.rbs +2 -82
  21. data/sig/domainic/type/behavior/uri_behavior.rbs +95 -0
  22. data/sig/domainic/type/behavior.rbs +9 -0
  23. data/sig/domainic/type/definitions.rbs +149 -1
  24. data/sig/domainic/type/types/identifier/cuid_type.rbs +110 -0
  25. data/sig/domainic/type/types/identifier/uuid_type.rbs +469 -0
  26. data/sig/domainic/type/types/network/email_address_type.rbs +127 -0
  27. data/sig/domainic/type/types/network/hostname_type.rbs +76 -0
  28. data/sig/domainic/type/types/network/uri_type.rbs +159 -0
  29. metadata +20 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 56d315e14fd05fe94174f580d09843c227cc5d763e994b47fd4094c26365dafc
4
- data.tar.gz: cf0288834c42fdd9d985ddb889484273dbae5278e0b8f0f1bd0021317c0387ae
3
+ metadata.gz: ba2ef6a6a8d06966d736c794476322b088878573154468dc55de61a85704f459
4
+ data.tar.gz: 8f7fcb77831968e9f6f4f42c58bc2f63892b56bae35902aec892932dc5425acc
5
5
  SHA512:
6
- metadata.gz: d53f6f1acc6969c093bb3617acb04ec17d507571c514604c941e378ad80341e7145d5f15298ec4922e68fc646e5f984cfc3e49fa8a7f2ab501d30456329dc9a4
7
- data.tar.gz: 9e5a0a9815c013086aeb5d183b66f2dfa3e0db4c31d62b8357ce0a2a12ca5bd3aafdad0a94d8c01781171a61df7a37d9dacd21b5d9d9256fe218ce62bc7b81e7
6
+ metadata.gz: 8fbe93a49fd3d0063c7d9e392cc1e99180cbdfacb3a1a355c813eaa3df5f476be03e6c44b265871bdea82c646c250b5f486b4446f8c0ce2efbc4481c778d5553
7
+ data.tar.gz: 2509ae814a1dbb07a2100c24fe0aff90b8c59123f41d8b37a90bce60c9ad33fe1ecd9d57562533e3f7c52f5c051c27120136d1d7f1efe1df4714212281663827
@@ -0,0 +1,115 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Domainic
4
+ module Type
5
+ module Behavior
6
+ module StringBehavior
7
+ # A module providing string matching constraint methods
8
+ #
9
+ # This module extends types with methods for constraining string values based on
10
+ # equality, pattern matching, and substring inclusion/exclusion. It provides a
11
+ # fluent interface for building complex string matching constraints.
12
+ #
13
+ # @example Basic equality constraints
14
+ # type = StringType.new
15
+ # .being_equal_to("expected")
16
+ # .not_being_equal_to("forbidden")
17
+ #
18
+ # @example Pattern matching constraints
19
+ # type = StringType.new
20
+ # .matching(/^\w+$/, /[0-9]/)
21
+ # .not_matching(/admin/i)
22
+ #
23
+ # @example Substring constraints
24
+ # type = StringType.new
25
+ # .containing("allowed", "required")
26
+ # .excluding("forbidden", "blocked")
27
+ #
28
+ # @author {https://aaronmallen.me Aaron Allen}
29
+ # @since 0.1.0
30
+ module MatchingBehavior
31
+ # Constrain string to equal a specific value
32
+ #
33
+ # @param literal [String, Symbol] the value to match against
34
+ # @return [Behavior] self for method chaining
35
+ # @rbs (String | Symbol literal) -> Behavior
36
+ def being_equal_to(literal)
37
+ # @type self: Object & Behavior
38
+ constrain :self, :equality, literal, description: 'equaling'
39
+ end
40
+ alias eql being_equal_to
41
+ alias equal_to being_equal_to
42
+ alias equaling being_equal_to
43
+
44
+ # Constrain string to contain specific substrings
45
+ #
46
+ # @param literals [Array<String, Symbol>] the required substrings
47
+ # @return [Behavior] self for method chaining
48
+ # @rbs (*String | Symbol literals) -> Behavior
49
+ def containing(*literals)
50
+ # @type self: Object & Behavior
51
+ including = literals.map do |literal|
52
+ @constraints.prepare :self, :inclusion, literal, coerce_with: lambda(&:to_s)
53
+ end
54
+ constrain :self, :and, including, concerning: :inclusion
55
+ end
56
+ alias including containing
57
+
58
+ # Constrain string to exclude specific substrings
59
+ #
60
+ # @param literals [Array<String, Symbol>] the forbidden substrings
61
+ # @return [Behavior] self for method chaining
62
+ # @rbs (*String | Symbol literals) -> Behavior
63
+ def excluding(*literals)
64
+ # @type self: Object & Behavior
65
+ including = literals.map do |literal|
66
+ @constraints.prepare :self, :inclusion, literal, coerce_with: lambda(&:to_s)
67
+ end
68
+ constrain :self, :nor, including, concerning: :exclusion
69
+ end
70
+ alias omitting excluding
71
+
72
+ # Constrain string to match specific patterns
73
+ #
74
+ # @param patterns [Array<String, Regexp>] the required patterns
75
+ # @return [Behavior] self for method chaining
76
+ # @rbs (*String | Regexp patterns) -> Behavior
77
+ def matching(*patterns)
78
+ # @type self: Object & Behavior
79
+ matching_patterns = patterns.map do |pattern|
80
+ @constraints.prepare :self, :match_pattern, pattern
81
+ end
82
+ constrain :self, :and, matching_patterns, concerning: :pattern_inclusion
83
+ end
84
+
85
+ # Constrain string to not equal a specific value
86
+ #
87
+ # @param literal [String, Symbol] the forbidden value
88
+ # @return [Behavior] self for method chaining
89
+ # @rbs (String | Symbol literal) -> Behavior
90
+ def not_being_equal_to(literal)
91
+ # @type self: Object & Behavior
92
+ equal_to = @constraints.prepare :self, :equality, literal
93
+ constrain :self, :not, equal_to, concerning: :equality, description: 'being'
94
+ end
95
+ alias not_eql not_being_equal_to
96
+ alias not_equal_to not_being_equal_to
97
+ alias not_equaling not_being_equal_to
98
+
99
+ # Constrain string to not match specific patterns
100
+ #
101
+ # @param patterns [Array<String, Regexp>] the forbidden patterns
102
+ # @return [Behavior] self for method chaining
103
+ # @rbs (*String | Regexp patterns) -> Behavior
104
+ def not_matching(*patterns)
105
+ # @type self: Object & Behavior
106
+ matching_patterns = patterns.map do |pattern|
107
+ @constraints.prepare :self, :match_pattern, pattern
108
+ end
109
+ constrain :self, :nor, matching_patterns, concerning: :pattern_exclusion
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'domainic/type/behavior/string_behavior/matching_behavior'
3
4
  require 'domainic/type/behavior/sizable_behavior'
4
5
 
5
6
  module Domainic
@@ -54,6 +55,7 @@ module Domainic
54
55
  # @author {https://aaronmallen.me Aaron Allen}
55
56
  # @since 0.1.0
56
57
  module StringBehavior
58
+ include MatchingBehavior
57
59
  include SizableBehavior
58
60
 
59
61
  # Validate string contains only alphanumeric characters.
@@ -102,24 +104,6 @@ module Domainic
102
104
  end
103
105
  alias empty being_empty
104
106
 
105
- # Validate string equals a specific value.
106
- #
107
- # @example
108
- # type.being_equal_to("hello")
109
- # type.validate("hello") # => true
110
- # type.validate("world") # => false
111
- #
112
- # @param literal [String, Symbol] the value to compare against
113
- # @return [Behavior] self for method chaining
114
- # @rbs (String | Symbol literal) -> Behavior
115
- def being_equal_to(literal)
116
- # @type self: Object & Behavior
117
- constrain :self, :equality, literal, description: 'equaling'
118
- end
119
- alias eql being_equal_to
120
- alias equal_to being_equal_to
121
- alias equaling being_equal_to
122
-
123
107
  # Validate string is lowercase.
124
108
  #
125
109
  # @example
@@ -266,62 +250,6 @@ module Domainic
266
250
  alias not_being_lowercase being_uppercase
267
251
  alias uppercase being_uppercase
268
252
 
269
- # Validate string contains all specified substrings.
270
- #
271
- # @example
272
- # type.containing("hello", "world")
273
- # type.validate("hello world") # => true
274
- # type.validate("hello") # => false
275
- #
276
- # @param literals [Array<String, Symbol>] the substrings to look for
277
- # @return [Behavior] self for method chaining
278
- # @rbs (*String | Symbol literals) -> Behavior
279
- def containing(*literals)
280
- # @type self: Object & Behavior
281
- including = literals.map do |literal|
282
- @constraints.prepare :self, :inclusion, literal, coerce_with: lambda(&:to_s)
283
- end
284
- constrain :self, :and, including, concerning: :inclusion
285
- end
286
- alias including containing
287
-
288
- # Validate string does not contain any specified substrings.
289
- #
290
- # @example
291
- # type.excluding("foo", "bar")
292
- # type.validate("hello world") # => true
293
- # type.validate("foo bar") # => false
294
- #
295
- # @param literals [Array<String, Symbol>] the substrings to exclude
296
- # @return [Behavior] self for method chaining
297
- # @rbs (*String | Symbol literals) -> Behavior
298
- def excluding(*literals)
299
- # @type self: Object & Behavior
300
- including = literals.map do |literal|
301
- @constraints.prepare :self, :inclusion, literal, coerce_with: lambda(&:to_s)
302
- end
303
- constrain :self, :nor, including, concerning: :exclusion
304
- end
305
- alias omitting excluding
306
-
307
- # Validate string matches all specified patterns.
308
- #
309
- # @example
310
- # type.matching(/^\w+$/, /\d/)
311
- # type.validate("hello123") # => true
312
- # type.validate("hello") # => false
313
- #
314
- # @param patterns [Array<String, Regexp>] the patterns to match against
315
- # @return [Behavior] self for method chaining
316
- # @rbs (*String | Regexp patterns) -> Behavior
317
- def matching(*patterns)
318
- # @type self: Object & Behavior
319
- matching_patterns = patterns.map do |pattern|
320
- @constraints.prepare :self, :match_pattern, pattern
321
- end
322
- constrain :self, :and, matching_patterns, concerning: :pattern_inclusion
323
- end
324
-
325
253
  # Validate string is not empty.
326
254
  #
327
255
  # @example
@@ -336,43 +264,6 @@ module Domainic
336
264
  empty = @constraints.prepare :self, :emptiness
337
265
  constrain :self, :not, empty, concerning: :emptiness, description: 'being'
338
266
  end
339
-
340
- # Validate string does not equal a specific value.
341
- #
342
- # @example
343
- # type.not_being_equal_to("admin")
344
- # type.validate("user") # => true
345
- # type.validate("admin") # => false
346
- #
347
- # @param literal [String, Symbol] the value to compare against
348
- # @return [Behavior] self for method chaining
349
- # @rbs (String | Symbol literal) -> Behavior
350
- def not_being_equal_to(literal)
351
- # @type self: Object & Behavior
352
- equal_to = @constraints.prepare :self, :equality, literal
353
- constrain :self, :not, equal_to, concerning: :equality, description: 'being'
354
- end
355
- alias not_eql not_being_equal_to
356
- alias not_equal_to not_being_equal_to
357
- alias not_equaling not_being_equal_to
358
-
359
- # Validate string does not match any specified patterns.
360
- #
361
- # @example
362
- # type.not_matching(/\d/, /[A-Z]/)
363
- # type.validate("hello") # => true
364
- # type.validate("Hello123") # => false
365
- #
366
- # @param patterns [Array<String, Regexp>] the patterns to avoid matching
367
- # @return [Behavior] self for method chaining
368
- # @rbs (*String | Regexp patterns) -> Behavior
369
- def not_matching(*patterns)
370
- # @type self: Object & Behavior
371
- matching_patterns = patterns.map do |pattern|
372
- @constraints.prepare :self, :match_pattern, pattern
373
- end
374
- constrain :self, :nor, matching_patterns, concerning: :pattern_exclusion
375
- end
376
267
  end
377
268
  end
378
269
  end
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Domainic
4
+ module Type
5
+ module Behavior
6
+ # A module providing URI-based validation behaviors for types.
7
+ #
8
+ # This module extends the base Type::Behavior with methods designed for validating URI-related constraints.
9
+ # It focuses on ensuring URIs conform to specific rules, such as restricting or excluding particular
10
+ # top-level domains (TLDs). These features are useful for scenarios like domain-specific validations
11
+ # or blocking specific domain extensions.
12
+ #
13
+ # Key features:
14
+ # - Top-level domain inclusion constraints
15
+ # - Top-level domain exclusion constraints
16
+ # - Flexible and customizable pattern matching
17
+ # - Consistent interface for defining URI-related constraints
18
+ #
19
+ # @example Basic usage
20
+ # class MyType
21
+ # include Domainic::Type::Behavior::URIBehavior
22
+ #
23
+ # def initialize
24
+ # super
25
+ # having_top_level_domain("com", "org") # Allow only .com and .org
26
+ # not_having_top_level_domain("test", "dev") # Exclude .test and .dev
27
+ # end
28
+ # end
29
+ #
30
+ # @example Method aliases
31
+ # type.having_top_level_domain("com") # Allow only .com
32
+ # type.tld("com") # Same as above
33
+ # type.with_tld("com") # Same as above
34
+ #
35
+ # type.not_having_top_level_domain("test") # Exclude .test
36
+ # type.not_tld("test") # Same as above
37
+ # type.not_top_level_domain("test") # Same as above
38
+ #
39
+ # This module provides a consistent interface for working with URIs, ensuring flexibility and
40
+ # extensibility for domain and TLD validation tasks.
41
+ #
42
+ # @author {https://aaronmallen.me Aaron Allen}
43
+ # @since 0.1.0
44
+ module URIBehavior
45
+ # Constrain URIBehavior to allowed top-level domains
46
+ #
47
+ # Creates a constraint ensuring the URIBehavior uses one of the specified top-level
48
+ # domains (TLDs). This allows restricting emails to specific TLDs like .com or .org.
49
+ #
50
+ # @example
51
+ # type.having_top_level_domain("com", "org")
52
+ # type.validate("example.com") # => true
53
+ # type.validate("example.net") # => false
54
+ #
55
+ # @param top_level_domains [Array<String>] List of allowed TLDs
56
+ # @return [self] self for method chaining
57
+ # @rbs (*String top_level_domains) -> Behavior
58
+ def having_top_level_domain(*top_level_domains)
59
+ pattern = /\.(#{top_level_domains.map { |t| Regexp.escape(t) }.join('|')})\z/i
60
+ # @type self: Object & Behavior
61
+ constrain :self, :match_pattern, pattern, concerning: :top_level_domain_inclusion
62
+ end
63
+ alias allowing_tld having_top_level_domain
64
+ alias allowing_top_level_domain having_top_level_domain
65
+ alias having_tld having_top_level_domain
66
+ alias tld having_top_level_domain
67
+ alias with_tld having_top_level_domain
68
+ alias with_top_level_domain having_top_level_domain
69
+
70
+ # Constrain URIBehavior to exclude specific top-level domains
71
+ #
72
+ # Creates a constraint ensuring the email does not use any of the specified
73
+ # top-level domains (TLDs). Useful for blocking certain TLDs.
74
+ #
75
+ # @example
76
+ # type.not_having_top_level_domain("test")
77
+ # type.validate("example.com") # => true
78
+ # type.validate("example.test") # => false
79
+ #
80
+ # @param top_level_domains [Array<String>] List of forbidden TLDs
81
+ # @return [self] self for method chaining
82
+ # @rbs (*String top_level_domains) -> Behavior
83
+ def not_having_top_level_domain(*top_level_domains)
84
+ pattern = /\.(#{top_level_domains.map { |t| Regexp.escape(t) }.join('|')})\z/i
85
+ top_level_domains = @constraints.prepare :self, :match_pattern, pattern
86
+ # @type self: Object & Behavior
87
+ constrain :self, :not, top_level_domains, concerning: :top_level_domain_exclusion
88
+ end
89
+ alias forbidding_tld not_having_top_level_domain
90
+ alias forbidding_top_level_domain not_having_top_level_domain
91
+ alias not_having_tld not_having_top_level_domain
92
+ alias not_tld not_having_top_level_domain
93
+ alias not_top_level_domain not_having_top_level_domain
94
+ end
95
+ end
96
+ end
97
+ end
@@ -105,6 +105,8 @@ module Domainic
105
105
  #
106
106
  # @see Constraint::Set#add
107
107
  #
108
+ # @deprecated Use {#intrinsically_constrain} instead
109
+ #
108
110
  # @return [void]
109
111
  # @rbs (
110
112
  # Type::accessor accessor,
@@ -113,7 +115,10 @@ module Domainic
113
115
  # **untyped options
114
116
  # ) -> void
115
117
  def intrinsic(...)
116
- intrinsic_constraints.add(...)
118
+ warn 'Domainic::Type::Behavior.intrinsic is deprecated and will be remove in a future release. Use ' \
119
+ "Domainic::Type::Behavior.intrinsically_constrain instead.\n" \
120
+ "Called from: #{caller_locations(1..1)&.first}"
121
+ intrinsically_constrain(...)
117
122
  end
118
123
 
119
124
  # Get the set of intrinsic constraints for this type.
@@ -124,6 +129,21 @@ module Domainic
124
129
  @intrinsic_constraints ||= Constraint::Set.new
125
130
  end
126
131
 
132
+ # Add an intrinsic constraint to this type.
133
+ #
134
+ # @see Constraint::Set#add
135
+ #
136
+ # @return [void]
137
+ # @rbs (
138
+ # Type::accessor accessor,
139
+ # String | Symbol constraint_type,
140
+ # ?untyped expectation,
141
+ # **untyped options
142
+ # ) -> void
143
+ def intrinsically_constrain(...)
144
+ intrinsic_constraints.add(...)
145
+ end
146
+
127
147
  # Delegate unknown methods to a new instance.
128
148
  #
129
149
  # @return [Object] The result of calling the method on a new instance
@@ -78,9 +78,15 @@ types:
78
78
  anything:
79
79
  constant: Domainic::Type::AnythingType
80
80
  require_path: domainic/type/types/specification/anything_type
81
+ cuid:
82
+ constant: Domainic::Type::CUIDType
83
+ require_path: domainic/type/types/identifier/cuid_type
81
84
  duck:
82
85
  constant: Domainic::Type::DuckType
83
86
  require_path: domainic/type/types/specification/duck_type
87
+ email_address:
88
+ constant: Domainic::Type::EmailAddressType
89
+ require_path: domainic/type/types/network/email_address_type
84
90
  enum:
85
91
  constant: Domainic::Type::EnumType
86
92
  require_path: domainic/type/types/specification/enum_type
@@ -90,6 +96,9 @@ types:
90
96
  hash:
91
97
  constant: Domainic::Type::HashType
92
98
  require_path: domainic/type/types/core/hash_type
99
+ hostname:
100
+ constant: Domainic::Type::HostnameType
101
+ require_path: domainic/type/types/network/hostname_type
93
102
  instance_type:
94
103
  constant: Domainic::Type::InstanceType
95
104
  require_path: domainic/type/types/specialized/instance_type
@@ -105,6 +114,12 @@ types:
105
114
  union:
106
115
  constant: Domainic::Type::UnionType
107
116
  require_path: domainic/type/types/specification/union_type
117
+ uri:
118
+ constant: Domainic::Type::URIType
119
+ require_path: domainic/type/types/network/uri_type
120
+ uuid:
121
+ constant: Domainic::Type::UUIDType
122
+ require_path: domainic/type/types/identifier/uuid_type
108
123
  void:
109
124
  constant: Domainic::Type::VoidType
110
125
  require_path: domainic/type/types/specification/void_type
@@ -103,6 +103,36 @@ module Domainic
103
103
  end
104
104
  alias _Bool? _Boolean?
105
105
 
106
+ # Creates a CUIDType instance
107
+ #
108
+ # @example
109
+ # type = _CUID.v2
110
+ #
111
+ # @param options [Hash] additional configuration options
112
+ #
113
+ # @return [Domainic::Type::CUIDType] the created type
114
+ # @rbs (**__todo__ options) -> CUIDType
115
+ def _CUID(**options)
116
+ require 'domainic/type/types/identifier/cuid_type'
117
+ Domainic::Type::CUIDType.new(**options)
118
+ end
119
+ alias _Cuid _CUID
120
+
121
+ # Creates a nilable CUIDType instance.
122
+ #
123
+ # @example
124
+ # _CUID? === "la6m1dv00000gv25zp9ru12g" # => true
125
+ # _CUID? === nil # => true
126
+ #
127
+ # @param options [Hash] additional configuration options
128
+ #
129
+ # @return [Domainic::Type::UnionType] the created type (CUIDType or NilClass)
130
+ # @rbs (**__todo__ options) -> UnionType
131
+ def _CUID?(**options)
132
+ _Nilable(_CUID(**options))
133
+ end
134
+ alias _Cuid? _CUID?
135
+
106
136
  # Creates a DuckType instance.
107
137
  #
108
138
  # DuckType allows specifying behavior based on method availability.
@@ -122,6 +152,38 @@ module Domainic
122
152
  alias _Protocol _Duck
123
153
  alias _RespondingTo _Duck
124
154
 
155
+ # Creates an EmailAddressType instance.
156
+ #
157
+ # EmailAddressType restricts values to valid email addresses.
158
+ #
159
+ # @example
160
+ # type = _EmailAddress.having_hostname('example.com')
161
+ #
162
+ # @param options [Hash] additional configuration options
163
+ #
164
+ # @return [Domainic::Type::EmailAddressType] the created type
165
+ # @rbs (**__todo__ options) -> EmailAddressType
166
+ def _EmailAddress(**options)
167
+ require 'domainic/type/types/network/email_address_type'
168
+ Domainic::Type::EmailAddressType.new(**options)
169
+ end
170
+ alias _Email _EmailAddress
171
+
172
+ # Creates a nilable EmailAddressType instance.
173
+ #
174
+ # @example
175
+ # _EmailAddress?.validate("user@example.com") # => true
176
+ # _EmailAddress?.validate(nil) # => true
177
+ #
178
+ # @param options [Hash] additional configuration options
179
+ #
180
+ # @return [Domainic::Type::UnionType] the created type (EmailAddress or NilClass)
181
+ # @rbs (**__todo__ options) -> UnionType
182
+ def _EmailAddress?(**options)
183
+ _Nilable(_EmailAddress(**options))
184
+ end
185
+ alias _Email? _EmailAddress?
186
+
125
187
  # Creates an EnumType instance.
126
188
  #
127
189
  # EnumType restricts values to a specific set of literals.
@@ -218,6 +280,63 @@ module Domainic
218
280
  end
219
281
  alias _Map? _Hash?
220
282
 
283
+ # Creates a HostnameType instance.
284
+ #
285
+ # HostnameType restricts values to valid hostnames.
286
+ #
287
+ # @example
288
+ # type = _Hostname.matching('example.com')
289
+ #
290
+ # @param options [Hash] additional configuration options
291
+ #
292
+ # @return [Domainic::Type::HostnameType] the created type
293
+ # @rbs (**__todo__ options) -> HostnameType
294
+ def _Hostname(**options)
295
+ require 'domainic/type/types/network/hostname_type'
296
+ Domainic::Type::HostnameType.new(**options)
297
+ end
298
+
299
+ # Creates a nilable HostnameType instance.
300
+ #
301
+ # @example
302
+ # _Hostname?.validate("example.com") # => true
303
+ # _Hostname?.validate(nil) # => true
304
+ #
305
+ # @param options [Hash] additional configuration options
306
+ #
307
+ # @return [Domainic::Type::UnionType] the created type (Hostname or NilClass)
308
+ # @rbs (**__todo__ options) -> UnionType
309
+ def _Hostname?(**options)
310
+ _Nilable(_Hostname(**options))
311
+ end
312
+
313
+ # Creates a UnionType of IntegerType, UUIDType, and CUIDType
314
+ #
315
+ # @example
316
+ # _ID === 1234567890 # => true
317
+ # _ID === '123e4567-e89b-42d3-a456-426614174000' # => true
318
+ # _ID === 'la6m1dv00000gv25zp9ru12g' # => true
319
+ #
320
+ # @return [Domainic::Type::UnionType] the created type
321
+ # @rbs () -> UnionType
322
+ def _ID
323
+ _Union(_Integer, _UUID, _CUID)
324
+ end
325
+
326
+ # Creates a nilable UnionType of IntegerType, UUIDType, and CUIDType
327
+ #
328
+ # @example
329
+ # _ID === 1234567890 # => true
330
+ # _ID === '123e4567-e89b-42d3-a456-426614174000' # => true
331
+ # _ID === 'la6m1dv00000gv25zp9ru12g' # => true
332
+ # _ID === nil # => true
333
+ #
334
+ # @return [Domainic::Type::UnionType] the created type
335
+ # @rbs () -> UnionType
336
+ def _ID?
337
+ _Nilable(_ID)
338
+ end
339
+
221
340
  # Create an InstanceType instance.
222
341
  #
223
342
  # @example
@@ -240,7 +359,7 @@ module Domainic
240
359
  #
241
360
  # @param options [Hash] additional configuration options
242
361
  #
243
- # @return [Domainic::Type::UnionType] the created type (Integer or NilClass)
362
+ # @return [Domainic::Type::UnionType] the created type (InstanceType or NilClass)
244
363
  # @rbs (**__todo__ options) -> UnionType
245
364
  def _Instance?(**options)
246
365
  _Nilable(_Instance(**options))
@@ -356,6 +475,36 @@ module Domainic
356
475
  end
357
476
  alias _Interned? _Symbol?
358
477
 
478
+ # Creates a UUIDType instance
479
+ #
480
+ # @example
481
+ # type = _UUID.v4_compact
482
+ #
483
+ # @param options [Hash] additional configuration options
484
+ #
485
+ # @return [Domainic::Type::UUIDType] the created type
486
+ # @rbs (**__todo__ options) -> UUIDType
487
+ def _UUID(**options)
488
+ require 'domainic/type/types/identifier/uuid_type'
489
+ Domainic::Type::UUIDType.new(**options)
490
+ end
491
+ alias _Uuid _UUID
492
+
493
+ # Creates a nilable UUIDType instance.
494
+ #
495
+ # @example
496
+ # _UUID? === '123e4567-e89b-42d3-a456-426614174000' # => true
497
+ # _UUID? === nil # => true
498
+ #
499
+ # @param options [Hash] additional configuration options
500
+ #
501
+ # @return [Domainic::Type::UnionType] the created type (UUIDType or NilClass)
502
+ # @rbs (**__todo__ options) -> UnionType
503
+ def _UUID?(**options)
504
+ _Nilable(_UUID(**options))
505
+ end
506
+ alias _Uuid? _UUID?
507
+
359
508
  # Creates a UnionType instance.
360
509
  #
361
510
  # Allows combining multiple types into a single union type.
@@ -374,6 +523,38 @@ module Domainic
374
523
  end
375
524
  alias _Either _Union
376
525
 
526
+ # Creates a URIType instance.
527
+ #
528
+ # URIType restricts values to valid URIs.
529
+ #
530
+ # @example
531
+ # type = _URI.having_scheme('https')
532
+ #
533
+ # @param options [Hash] additional configuration options
534
+ #
535
+ # @return [Domainic::Type::URIType] the created type
536
+ # @rbs (**__todo__ options) -> URIType
537
+ def _Uri(**options)
538
+ require 'domainic/type/types/network/uri_type'
539
+ Domainic::Type::URIType.new(**options)
540
+ end
541
+ alias _Url _Uri
542
+
543
+ # Creates a nilable URIType instance.
544
+ #
545
+ # @example
546
+ # _Uri?.validate("https://example.com") # => true
547
+ # _Uri?.validate(nil) # => true
548
+ #
549
+ # @param options [Hash] additional configuration options
550
+ #
551
+ # @return [Domainic::Type::UnionType] the created type (URIType or NilClass)
552
+ # @rbs (**__todo__ options) -> UnionType
553
+ def _Uri?(**options)
554
+ _Nilable(_Uri(**options))
555
+ end
556
+ alias _Url? _Uri?
557
+
377
558
  # Creates a VoidType instance.
378
559
  #
379
560
  # Represents an operation that returns no value.
@@ -42,7 +42,7 @@ module Domainic
42
42
  include Behavior
43
43
  include Behavior::EnumerableBehavior
44
44
 
45
- intrinsic :self, :type, Array, abort_on_failure: true, description: :not_described
45
+ intrinsically_constrain :self, :type, Array, abort_on_failure: true, description: :not_described
46
46
  end
47
47
  end
48
48
  end