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.
- checksums.yaml +4 -4
- data/lib/domainic/type/behavior/string_behavior/matching_behavior.rb +115 -0
- data/lib/domainic/type/behavior/string_behavior.rb +2 -111
- data/lib/domainic/type/behavior/uri_behavior.rb +97 -0
- data/lib/domainic/type/behavior.rb +21 -1
- data/lib/domainic/type/config/registry.yml +15 -0
- data/lib/domainic/type/definitions.rb +182 -1
- data/lib/domainic/type/types/core/array_type.rb +1 -1
- data/lib/domainic/type/types/core/float_type.rb +1 -1
- data/lib/domainic/type/types/core/hash_type.rb +1 -1
- data/lib/domainic/type/types/core/integer_type.rb +1 -1
- data/lib/domainic/type/types/core/string_type.rb +1 -1
- data/lib/domainic/type/types/core/symbol_type.rb +1 -1
- data/lib/domainic/type/types/identifier/cuid_type.rb +140 -0
- data/lib/domainic/type/types/identifier/uuid_type.rb +513 -0
- data/lib/domainic/type/types/network/email_address_type.rb +149 -0
- data/lib/domainic/type/types/network/hostname_type.rb +107 -0
- data/lib/domainic/type/types/network/uri_type.rb +224 -0
- data/sig/domainic/type/behavior/string_behavior/matching_behavior.rbs +84 -0
- data/sig/domainic/type/behavior/string_behavior.rbs +2 -82
- data/sig/domainic/type/behavior/uri_behavior.rbs +95 -0
- data/sig/domainic/type/behavior.rbs +9 -0
- data/sig/domainic/type/definitions.rbs +149 -1
- data/sig/domainic/type/types/identifier/cuid_type.rbs +110 -0
- data/sig/domainic/type/types/identifier/uuid_type.rbs +469 -0
- data/sig/domainic/type/types/network/email_address_type.rbs +127 -0
- data/sig/domainic/type/types/network/hostname_type.rbs +76 -0
- data/sig/domainic/type/types/network/uri_type.rbs +159 -0
- metadata +20 -6
@@ -86,6 +86,31 @@ module Domainic
|
|
86
86
|
|
87
87
|
alias _Bool? _Boolean?
|
88
88
|
|
89
|
+
# Creates a CUIDType instance
|
90
|
+
#
|
91
|
+
# @example
|
92
|
+
# type = _CUID.v2
|
93
|
+
#
|
94
|
+
# @param options [Hash] additional configuration options
|
95
|
+
#
|
96
|
+
# @return [Domainic::Type::CUIDType] the created type
|
97
|
+
def _CUID: (**__todo__ options) -> CUIDType
|
98
|
+
|
99
|
+
alias _Cuid _CUID
|
100
|
+
|
101
|
+
# Creates a nilable CUIDType instance.
|
102
|
+
#
|
103
|
+
# @example
|
104
|
+
# _CUID? === "la6m1dv00000gv25zp9ru12g" # => true
|
105
|
+
# _CUID? === nil # => true
|
106
|
+
#
|
107
|
+
# @param options [Hash] additional configuration options
|
108
|
+
#
|
109
|
+
# @return [Domainic::Type::UnionType] the created type (CUIDType or NilClass)
|
110
|
+
def _CUID?: (**__todo__ options) -> UnionType
|
111
|
+
|
112
|
+
alias _Cuid? _CUID?
|
113
|
+
|
89
114
|
# Creates a DuckType instance.
|
90
115
|
#
|
91
116
|
# DuckType allows specifying behavior based on method availability.
|
@@ -104,6 +129,33 @@ module Domainic
|
|
104
129
|
|
105
130
|
alias _RespondingTo _Duck
|
106
131
|
|
132
|
+
# Creates an EmailAddressType instance.
|
133
|
+
#
|
134
|
+
# EmailAddressType restricts values to valid email addresses.
|
135
|
+
#
|
136
|
+
# @example
|
137
|
+
# type = _EmailAddress.having_hostname('example.com')
|
138
|
+
#
|
139
|
+
# @param options [Hash] additional configuration options
|
140
|
+
#
|
141
|
+
# @return [Domainic::Type::EmailAddressType] the created type
|
142
|
+
def _EmailAddress: (**__todo__ options) -> EmailAddressType
|
143
|
+
|
144
|
+
alias _Email _EmailAddress
|
145
|
+
|
146
|
+
# Creates a nilable EmailAddressType instance.
|
147
|
+
#
|
148
|
+
# @example
|
149
|
+
# _EmailAddress?.validate("user@example.com") # => true
|
150
|
+
# _EmailAddress?.validate(nil) # => true
|
151
|
+
#
|
152
|
+
# @param options [Hash] additional configuration options
|
153
|
+
#
|
154
|
+
# @return [Domainic::Type::UnionType] the created type (EmailAddress or NilClass)
|
155
|
+
def _EmailAddress?: (**__todo__ options) -> UnionType
|
156
|
+
|
157
|
+
alias _Email? _EmailAddress?
|
158
|
+
|
107
159
|
# Creates an EnumType instance.
|
108
160
|
#
|
109
161
|
# EnumType restricts values to a specific set of literals.
|
@@ -184,6 +236,50 @@ module Domainic
|
|
184
236
|
|
185
237
|
alias _Map? _Hash?
|
186
238
|
|
239
|
+
# Creates a HostnameType instance.
|
240
|
+
#
|
241
|
+
# HostnameType restricts values to valid hostnames.
|
242
|
+
#
|
243
|
+
# @example
|
244
|
+
# type = _Hostname.matching('example.com')
|
245
|
+
#
|
246
|
+
# @param options [Hash] additional configuration options
|
247
|
+
#
|
248
|
+
# @return [Domainic::Type::HostnameType] the created type
|
249
|
+
def _Hostname: (**__todo__ options) -> HostnameType
|
250
|
+
|
251
|
+
# Creates a nilable HostnameType instance.
|
252
|
+
#
|
253
|
+
# @example
|
254
|
+
# _Hostname?.validate("example.com") # => true
|
255
|
+
# _Hostname?.validate(nil) # => true
|
256
|
+
#
|
257
|
+
# @param options [Hash] additional configuration options
|
258
|
+
#
|
259
|
+
# @return [Domainic::Type::UnionType] the created type (Hostname or NilClass)
|
260
|
+
def _Hostname?: (**__todo__ options) -> UnionType
|
261
|
+
|
262
|
+
# Creates a UnionType of IntegerType, UUIDType, and CUIDType
|
263
|
+
#
|
264
|
+
# @example
|
265
|
+
# _ID === 1234567890 # => true
|
266
|
+
# _ID === '123e4567-e89b-42d3-a456-426614174000' # => true
|
267
|
+
# _ID === 'la6m1dv00000gv25zp9ru12g' # => true
|
268
|
+
#
|
269
|
+
# @return [Domainic::Type::UnionType] the created type
|
270
|
+
def _ID: () -> UnionType
|
271
|
+
|
272
|
+
# Creates a nilable UnionType of IntegerType, UUIDType, and CUIDType
|
273
|
+
#
|
274
|
+
# @example
|
275
|
+
# _ID === 1234567890 # => true
|
276
|
+
# _ID === '123e4567-e89b-42d3-a456-426614174000' # => true
|
277
|
+
# _ID === 'la6m1dv00000gv25zp9ru12g' # => true
|
278
|
+
# _ID === nil # => true
|
279
|
+
#
|
280
|
+
# @return [Domainic::Type::UnionType] the created type
|
281
|
+
def _ID?: () -> UnionType
|
282
|
+
|
187
283
|
# Create an InstanceType instance.
|
188
284
|
#
|
189
285
|
# @example
|
@@ -203,7 +299,7 @@ module Domainic
|
|
203
299
|
#
|
204
300
|
# @param options [Hash] additional configuration options
|
205
301
|
#
|
206
|
-
# @return [Domainic::Type::UnionType] the created type (
|
302
|
+
# @return [Domainic::Type::UnionType] the created type (InstanceType or NilClass)
|
207
303
|
def _Instance?: (**__todo__ options) -> UnionType
|
208
304
|
|
209
305
|
alias _Record? _Instance?
|
@@ -299,6 +395,31 @@ module Domainic
|
|
299
395
|
|
300
396
|
alias _Interned? _Symbol?
|
301
397
|
|
398
|
+
# Creates a UUIDType instance
|
399
|
+
#
|
400
|
+
# @example
|
401
|
+
# type = _UUID.v4_compact
|
402
|
+
#
|
403
|
+
# @param options [Hash] additional configuration options
|
404
|
+
#
|
405
|
+
# @return [Domainic::Type::UUIDType] the created type
|
406
|
+
def _UUID: (**__todo__ options) -> UUIDType
|
407
|
+
|
408
|
+
alias _Uuid _UUID
|
409
|
+
|
410
|
+
# Creates a nilable UUIDType instance.
|
411
|
+
#
|
412
|
+
# @example
|
413
|
+
# _UUID? === '123e4567-e89b-42d3-a456-426614174000' # => true
|
414
|
+
# _UUID? === nil # => true
|
415
|
+
#
|
416
|
+
# @param options [Hash] additional configuration options
|
417
|
+
#
|
418
|
+
# @return [Domainic::Type::UnionType] the created type (UUIDType or NilClass)
|
419
|
+
def _UUID?: (**__todo__ options) -> UnionType
|
420
|
+
|
421
|
+
alias _Uuid? _UUID?
|
422
|
+
|
302
423
|
# Creates a UnionType instance.
|
303
424
|
#
|
304
425
|
# Allows combining multiple types into a single union type.
|
@@ -314,6 +435,33 @@ module Domainic
|
|
314
435
|
|
315
436
|
alias _Either _Union
|
316
437
|
|
438
|
+
# Creates a URIType instance.
|
439
|
+
#
|
440
|
+
# URIType restricts values to valid URIs.
|
441
|
+
#
|
442
|
+
# @example
|
443
|
+
# type = _URI.having_scheme('https')
|
444
|
+
#
|
445
|
+
# @param options [Hash] additional configuration options
|
446
|
+
#
|
447
|
+
# @return [Domainic::Type::URIType] the created type
|
448
|
+
def _Uri: (**__todo__ options) -> URIType
|
449
|
+
|
450
|
+
alias _Url _Uri
|
451
|
+
|
452
|
+
# Creates a nilable URIType instance.
|
453
|
+
#
|
454
|
+
# @example
|
455
|
+
# _Uri?.validate("https://example.com") # => true
|
456
|
+
# _Uri?.validate(nil) # => true
|
457
|
+
#
|
458
|
+
# @param options [Hash] additional configuration options
|
459
|
+
#
|
460
|
+
# @return [Domainic::Type::UnionType] the created type (URIType or NilClass)
|
461
|
+
def _Uri?: (**__todo__ options) -> UnionType
|
462
|
+
|
463
|
+
alias _Url? _Uri?
|
464
|
+
|
317
465
|
# Creates a VoidType instance.
|
318
466
|
#
|
319
467
|
# Represents an operation that returns no value.
|
@@ -0,0 +1,110 @@
|
|
1
|
+
module Domainic
|
2
|
+
module Type
|
3
|
+
# A type for validating CUIDs according to official specifications
|
4
|
+
#
|
5
|
+
# This type provides comprehensive CUID validation following the official
|
6
|
+
# CUID specifications. It supports both v1 and v2 formats, with proper
|
7
|
+
# format-specific validation.
|
8
|
+
#
|
9
|
+
# Key features:
|
10
|
+
# - CUID v1 validation (25 characters, c-prefix)
|
11
|
+
# - CUID v2 validation (variable length 14-24 chars)
|
12
|
+
# - Length validation
|
13
|
+
# - Character set validation
|
14
|
+
#
|
15
|
+
# @example Basic usage
|
16
|
+
# type = CUIDType.new
|
17
|
+
# type.validate("ch72gsb320000udocl363eofy") # => true
|
18
|
+
# type.validate("invalid") # => false
|
19
|
+
#
|
20
|
+
# @example With version constraints
|
21
|
+
# type = CUIDType.new.being_version(2)
|
22
|
+
# type.validate("clh3am1f30000udocbhqg4151") # => true
|
23
|
+
#
|
24
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
25
|
+
# @since 0.1.0
|
26
|
+
class CUIDType
|
27
|
+
extend Behavior::ClassMethods
|
28
|
+
|
29
|
+
include Behavior
|
30
|
+
|
31
|
+
# Contains CUID validation regular expressions and version-specific modules
|
32
|
+
#
|
33
|
+
# This module provides validation patterns for both CUID v1 and v2 formats,
|
34
|
+
# following the official specification.
|
35
|
+
#
|
36
|
+
# @since 0.1.0
|
37
|
+
module CUID
|
38
|
+
# Regular expression for CUID v1 format
|
39
|
+
#
|
40
|
+
# Validates CUIDs in v1 format: c-prefix + 24 lowercase alphanumeric chars
|
41
|
+
# Example: "ch72gsb320000udocl363eofy"
|
42
|
+
#
|
43
|
+
# @since 0.1.0
|
44
|
+
V1_REGEXP: Regexp
|
45
|
+
|
46
|
+
# Regular expression for CUID v2 format
|
47
|
+
#
|
48
|
+
# Validates CUIDs in v2 format: k-p prefix + 13-23 lowercase alphanumeric chars
|
49
|
+
# Example: "clh3am1f30000udocbhqg4151"
|
50
|
+
#
|
51
|
+
# @since 0.1.0
|
52
|
+
V2_REGEXP: Regexp
|
53
|
+
|
54
|
+
# Regular expression for any valid CUID (v1 or v2)
|
55
|
+
ALL_REGEXP: Regexp
|
56
|
+
end
|
57
|
+
|
58
|
+
# Constrain CUID to specific version
|
59
|
+
#
|
60
|
+
# Creates a constraint ensuring the CUID matches a specific version (1 or 2).
|
61
|
+
#
|
62
|
+
# @example
|
63
|
+
# type.being_version(1)
|
64
|
+
# type.validate("ch72gsb320000udocl363eofy") # => true
|
65
|
+
#
|
66
|
+
# @param version [Integer] CUID version (1 or 2)
|
67
|
+
# @return [self] self for method chaining
|
68
|
+
# @raise [ArgumentError] if version is neither 1 nor 2
|
69
|
+
def being_version: (Integer version) -> self
|
70
|
+
|
71
|
+
alias version being_version
|
72
|
+
|
73
|
+
# Constrain CUID to Version 1
|
74
|
+
#
|
75
|
+
# Creates a constraint ensuring the CUID is a Version 1 CUID.
|
76
|
+
# Version 1 CUIDs are 25 characters long and start with 'c'.
|
77
|
+
#
|
78
|
+
# @example
|
79
|
+
# type.being_version_one
|
80
|
+
# type.validate("ch72gsb320000udocl363eofy") # => true
|
81
|
+
#
|
82
|
+
# @return [self] self for method chaining
|
83
|
+
def being_version_one: () -> self
|
84
|
+
|
85
|
+
alias being_v1 being_version_one
|
86
|
+
|
87
|
+
alias v1 being_version_one
|
88
|
+
|
89
|
+
alias version_one being_version_one
|
90
|
+
|
91
|
+
# Constrain CUID to Version 2
|
92
|
+
#
|
93
|
+
# Creates a constraint ensuring the CUID is a Version 2 CUID.
|
94
|
+
# Version 2 CUIDs are 14-24 characters and start with k-p.
|
95
|
+
#
|
96
|
+
# @example
|
97
|
+
# type.being_version_two
|
98
|
+
# type.validate("clh3am1f30000udocbhqg4151") # => true
|
99
|
+
#
|
100
|
+
# @return [self] self for method chaining
|
101
|
+
def being_version_two: () -> self
|
102
|
+
|
103
|
+
alias being_v2 being_version_two
|
104
|
+
|
105
|
+
alias v2 being_version_two
|
106
|
+
|
107
|
+
alias version_two being_version_two
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|