smart_schema 0.12.1 → 0.12.2
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/.gitignore +12 -0
- data/.rspec +3 -0
- data/.rubocop.yml +20 -0
- data/CHANGELOG.md +106 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +266 -0
- data/LICENSE.txt +21 -0
- data/README.md +305 -0
- data/Rakefile +21 -0
- data/bin/console +8 -0
- data/bin/setup +8 -0
- data/lib/smart_core/schema/checker/reconciler/constructor.rb +60 -0
- data/lib/smart_core/schema/checker/reconciler/matcher/options.rb +33 -0
- data/lib/smart_core/schema/checker/reconciler/matcher/result.rb +87 -0
- data/lib/smart_core/schema/checker/reconciler/matcher/result_finalizer.rb +186 -0
- data/lib/smart_core/schema/checker/reconciler/matcher.rb +62 -0
- data/lib/smart_core/schema/checker/reconciler.rb +106 -0
- data/lib/smart_core/schema/checker/rules/base.rb +110 -0
- data/lib/smart_core/schema/checker/rules/extra_keys/failure.rb +24 -0
- data/lib/smart_core/schema/checker/rules/extra_keys/result.rb +37 -0
- data/lib/smart_core/schema/checker/rules/extra_keys/success.rb +30 -0
- data/lib/smart_core/schema/checker/rules/extra_keys.rb +31 -0
- data/lib/smart_core/schema/checker/rules/optional.rb +27 -0
- data/lib/smart_core/schema/checker/rules/options/empty.rb +43 -0
- data/lib/smart_core/schema/checker/rules/options/filled.rb +49 -0
- data/lib/smart_core/schema/checker/rules/options/type.rb +88 -0
- data/lib/smart_core/schema/checker/rules/options.rb +60 -0
- data/lib/smart_core/schema/checker/rules/required.rb +27 -0
- data/lib/smart_core/schema/checker/rules/requirement/optional.rb +36 -0
- data/lib/smart_core/schema/checker/rules/requirement/required.rb +36 -0
- data/lib/smart_core/schema/checker/rules/requirement/result.rb +95 -0
- data/lib/smart_core/schema/checker/rules/requirement.rb +9 -0
- data/lib/smart_core/schema/checker/rules/result/base.rb +44 -0
- data/lib/smart_core/schema/checker/rules/result/failure.rb +41 -0
- data/lib/smart_core/schema/checker/rules/result/success.rb +15 -0
- data/lib/smart_core/schema/checker/rules/result.rb +9 -0
- data/lib/smart_core/schema/checker/rules/type_aliases.rb +57 -0
- data/lib/smart_core/schema/checker/rules/verifier/result.rb +75 -0
- data/lib/smart_core/schema/checker/rules/verifier.rb +74 -0
- data/lib/smart_core/schema/checker/rules.rb +89 -0
- data/lib/smart_core/schema/checker/verifiable_hash.rb +65 -0
- data/lib/smart_core/schema/checker.rb +106 -0
- data/lib/smart_core/schema/configuration.rb +33 -0
- data/lib/smart_core/schema/dsl.rb +81 -0
- data/lib/smart_core/schema/errors.rb +65 -0
- data/lib/smart_core/schema/key_control.rb +39 -0
- data/lib/smart_core/schema/plugins/abstract.rb +55 -0
- data/lib/smart_core/schema/plugins/access_mixin.rb +47 -0
- data/lib/smart_core/schema/plugins/dry_types/dry_types/abstract_factory.rb +99 -0
- data/lib/smart_core/schema/plugins/dry_types/dry_types/operation/base.rb +9 -0
- data/lib/smart_core/schema/plugins/dry_types/dry_types/operation/cast.rb +21 -0
- data/lib/smart_core/schema/plugins/dry_types/dry_types/operation/valid.rb +16 -0
- data/lib/smart_core/schema/plugins/dry_types/dry_types/operation/validate.rb +19 -0
- data/lib/smart_core/schema/plugins/dry_types/dry_types/operation.rb +12 -0
- data/lib/smart_core/schema/plugins/dry_types/dry_types.rb +10 -0
- data/lib/smart_core/schema/plugins/dry_types/errors.rb +13 -0
- data/lib/smart_core/schema/plugins/dry_types.rb +27 -0
- data/lib/smart_core/schema/plugins/registry.rb +158 -0
- data/lib/smart_core/schema/plugins/registry_interface.rb +63 -0
- data/lib/smart_core/schema/plugins.rb +17 -0
- data/lib/smart_core/schema/result.rb +62 -0
- data/lib/smart_core/schema/type_system/interop/abstract_factory.rb +92 -0
- data/lib/smart_core/schema/type_system/interop/aliasing/alias_list.rb +131 -0
- data/lib/smart_core/schema/type_system/interop/aliasing.rb +72 -0
- data/lib/smart_core/schema/type_system/interop/operation.rb +30 -0
- data/lib/smart_core/schema/type_system/interop.rb +128 -0
- data/lib/smart_core/schema/type_system/registry.rb +162 -0
- data/lib/smart_core/schema/type_system/registry_interface.rb +87 -0
- data/lib/smart_core/schema/type_system/smart_types/abstract_factory.rb +99 -0
- data/lib/smart_core/schema/type_system/smart_types/operation/base.rb +8 -0
- data/lib/smart_core/schema/type_system/smart_types/operation/cast.rb +16 -0
- data/lib/smart_core/schema/type_system/smart_types/operation/valid.rb +16 -0
- data/lib/smart_core/schema/type_system/smart_types/operation/validate.rb +16 -0
- data/lib/smart_core/schema/type_system/smart_types/operation.rb +13 -0
- data/lib/smart_core/schema/type_system/smart_types.rb +48 -0
- data/lib/smart_core/schema/type_system.rb +16 -0
- data/lib/smart_core/schema/version.rb +14 -0
- data/lib/smart_core/schema.rb +67 -0
- data/smart_schema.gemspec +46 -0
- metadata +83 -3
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SmartCore::Schema::TypeSystem
|
|
4
|
+
# @api private
|
|
5
|
+
# @since 0.12.0
|
|
6
|
+
class DryTypes::AbstractFactory < Interop::AbstractFactory
|
|
7
|
+
class << self
|
|
8
|
+
# @param type [::Dry::Types::Type]
|
|
9
|
+
# @return [void]
|
|
10
|
+
#
|
|
11
|
+
# @raise [SmartCore::Schema::IncorrectTypeObjectError]
|
|
12
|
+
#
|
|
13
|
+
# @api private
|
|
14
|
+
# @since 0.12.0
|
|
15
|
+
def prevent_incompatible_type!(type)
|
|
16
|
+
unless type.is_a?(::Dry::Types::Type)
|
|
17
|
+
raise(
|
|
18
|
+
SmartCore::Schema::IncorrectTypeObjectError,
|
|
19
|
+
'Incorrect Dry::Types primitive ' \
|
|
20
|
+
'(type object should be an object of Dry::Types::Type)'
|
|
21
|
+
)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# @param type [Any]
|
|
26
|
+
# @return [String]
|
|
27
|
+
#
|
|
28
|
+
# @api private
|
|
29
|
+
# @since 0.12.0
|
|
30
|
+
def build_identifier(type)
|
|
31
|
+
type.name
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# @param type [::Dry::Types::Type]
|
|
35
|
+
# @return [SmartCore::Schema::TypeSystem::DryTypes::Operation::Valid]
|
|
36
|
+
#
|
|
37
|
+
# @api private
|
|
38
|
+
# @since 0.12.0
|
|
39
|
+
def build_valid_operation(type)
|
|
40
|
+
DryTypes::Operation::Valid.new(type)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# @return [::Dry::Types::Any]
|
|
44
|
+
#
|
|
45
|
+
# @api private
|
|
46
|
+
# @since 0.12.0
|
|
47
|
+
def generic_type_object
|
|
48
|
+
::Dry::Types::Any
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# @return [Class<::Dry::Types::Type>]
|
|
52
|
+
#
|
|
53
|
+
# @api private
|
|
54
|
+
# @since 0.12.0
|
|
55
|
+
def primitive_type_class
|
|
56
|
+
::Dry::Types::Type
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# @return [::Dry::Types::Type]
|
|
60
|
+
#
|
|
61
|
+
# @api private
|
|
62
|
+
# @since 0.12.1
|
|
63
|
+
def hash_type_object_for_nested_schemas
|
|
64
|
+
::Dry::Types['hash']
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# @param type [::Dry::Types::Type]
|
|
68
|
+
# @return [SmartCore::Schema::TypeSystem::DryTypes::Operation::Validate]
|
|
69
|
+
#
|
|
70
|
+
# @api private
|
|
71
|
+
# @since 0.12.0
|
|
72
|
+
def build_validate_operation(type)
|
|
73
|
+
DryTypes::Operation::Validate.new(type)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# @param type [::Dry::Types::Type]
|
|
77
|
+
# @return [SmartCore::Schema::TypeSystem::DryTypes::Operation::Cast]
|
|
78
|
+
#
|
|
79
|
+
# @api private
|
|
80
|
+
# @since 0.12.0
|
|
81
|
+
def build_cast_operation(type)
|
|
82
|
+
DryTypes::Operation::Cast.new(type)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# @param identifier [String]
|
|
86
|
+
# @param valid_op [SmartCore::Schema::TypeSystem::DryTypes::Operation::Valid]
|
|
87
|
+
# @param valid_op [SmartCore::Schema::TypeSystem::DryTypes::Operation::Validate]
|
|
88
|
+
# @param valid_op [SmartCore::Schema::TypeSystem::DryTypes::Operation::Cast]
|
|
89
|
+
# @return [SmartCore::Schema::TypeSystem::DryTypes]
|
|
90
|
+
#
|
|
91
|
+
# @api private
|
|
92
|
+
# @since 0.12.0
|
|
93
|
+
# @version 0.5.1
|
|
94
|
+
def build_interop(identifier, valid_op, validate_op, cast_op)
|
|
95
|
+
DryTypes.new(identifier, valid_op, validate_op, cast_op)
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SmartCore::Schema::TypeSystem::DryTypes::Operation
|
|
4
|
+
# @api private
|
|
5
|
+
# @since 0.12.0
|
|
6
|
+
class Cast < Base
|
|
7
|
+
# @param value [Any]
|
|
8
|
+
# @return [void]
|
|
9
|
+
#
|
|
10
|
+
# @raise [SmartCore::Schema::TypeCastingUnsupportedError]
|
|
11
|
+
#
|
|
12
|
+
# @api private
|
|
13
|
+
# @since 0.12.0
|
|
14
|
+
def call(value)
|
|
15
|
+
raise(
|
|
16
|
+
SmartCore::Schema::TypeCastingUnsupportedError,
|
|
17
|
+
'DryTypes type system has no support for type casting at the moment.'
|
|
18
|
+
)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SmartCore::Schema::TypeSystem::DryTypes::Operation
|
|
4
|
+
# @api private
|
|
5
|
+
# @since 0.12.0
|
|
6
|
+
class Valid < Base
|
|
7
|
+
# @param value [Any]
|
|
8
|
+
# @return [Boolean]
|
|
9
|
+
#
|
|
10
|
+
# @api private
|
|
11
|
+
# @since 0.12.0
|
|
12
|
+
def call(value)
|
|
13
|
+
type.valid?(value)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SmartCore::Schema::TypeSystem::DryTypes::Operation
|
|
4
|
+
# @api private
|
|
5
|
+
# @since 0.12.0
|
|
6
|
+
class Validate < Base
|
|
7
|
+
# @param value [Any]
|
|
8
|
+
# @return [void]
|
|
9
|
+
#
|
|
10
|
+
# @api private
|
|
11
|
+
# @since 0.12.0
|
|
12
|
+
def call(value)
|
|
13
|
+
raise(
|
|
14
|
+
SmartCore::Schema::DryTypesValidationError,
|
|
15
|
+
"Dry::Types validation error: (get #{value.inspect} for type #{type.inspect}"
|
|
16
|
+
) unless type.valid?(value)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SmartCore::Schema::TypeSystem
|
|
4
|
+
# @api private
|
|
5
|
+
# @since 0.12.0
|
|
6
|
+
module DryTypes::Operation
|
|
7
|
+
require_relative 'operation/base'
|
|
8
|
+
require_relative 'operation/valid'
|
|
9
|
+
require_relative 'operation/validate'
|
|
10
|
+
require_relative 'operation/cast'
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# rubocop:disable Style/StaticClass
|
|
4
|
+
class SmartCore::Schema
|
|
5
|
+
# @api public
|
|
6
|
+
# @since 0.12.0
|
|
7
|
+
DryTypesError = Class.new(SmartCore::Schema::Error)
|
|
8
|
+
|
|
9
|
+
# @api public
|
|
10
|
+
# @since 0.12.0
|
|
11
|
+
DryTypesValidationError = Class.new(DryTypesError)
|
|
12
|
+
end
|
|
13
|
+
# rubocop:enable Style/StaticClass
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# @api private
|
|
4
|
+
# @since 0.12.0
|
|
5
|
+
class SmartCore::Schema::Plugins::DryTypes < SmartCore::Schema::Plugins::Abstract
|
|
6
|
+
class << self
|
|
7
|
+
# @return [void]
|
|
8
|
+
#
|
|
9
|
+
# @api private
|
|
10
|
+
# @since 0.12.0
|
|
11
|
+
def install!
|
|
12
|
+
raise(
|
|
13
|
+
SmartCore::Schema::UnresolvedPluginDependencyError,
|
|
14
|
+
'::Dry::Types does not exist or "dry-types" gem is not loaded'
|
|
15
|
+
) unless const_defined?('::Dry::Types')
|
|
16
|
+
|
|
17
|
+
# NOTE: add dry-types type system implementation
|
|
18
|
+
require_relative 'dry_types/errors'
|
|
19
|
+
require_relative 'dry_types/dry_types'
|
|
20
|
+
|
|
21
|
+
# NOTE: register dry-types type system
|
|
22
|
+
SmartCore::Schema::TypeSystem.register(
|
|
23
|
+
:dry_types, SmartCore::Schema::TypeSystem::DryTypes
|
|
24
|
+
)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# @api private
|
|
4
|
+
# @since 0.12.0
|
|
5
|
+
class SmartCore::Schema::Plugins::Registry
|
|
6
|
+
# @since 0.12.0
|
|
7
|
+
include Enumerable
|
|
8
|
+
|
|
9
|
+
# @return [void]
|
|
10
|
+
#
|
|
11
|
+
# @api private
|
|
12
|
+
# @since 0.12.0
|
|
13
|
+
def initialize
|
|
14
|
+
@plugin_set = {}
|
|
15
|
+
@access_lock = SmartCore::Engine::ReadWriteLock.new
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# @param plugin_name [Symbol, String]
|
|
19
|
+
# @return [SmartCore::Schema::Plugins::Abstract]
|
|
20
|
+
#
|
|
21
|
+
# @api private
|
|
22
|
+
# @since 0.12.0
|
|
23
|
+
def [](plugin_name)
|
|
24
|
+
@access_lock.read_sync { fetch(plugin_name) }
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# @param plugin_name [Symbol, String]
|
|
28
|
+
# @param plugin_module [SmartCore::Schema::Plugins::Abstract]
|
|
29
|
+
# @return [void]
|
|
30
|
+
#
|
|
31
|
+
# @api private
|
|
32
|
+
# @since 0.12.0
|
|
33
|
+
def register(plugin_name, plugin_module)
|
|
34
|
+
@access_lock.write_sync { apply(plugin_name, plugin_module) }
|
|
35
|
+
end
|
|
36
|
+
alias_method :[]=, :register
|
|
37
|
+
|
|
38
|
+
# @return [Array<String>]
|
|
39
|
+
#
|
|
40
|
+
# @api private
|
|
41
|
+
# @since 0.12.0
|
|
42
|
+
def names
|
|
43
|
+
@access_lock.read_sync { plugin_names }
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# @return [Hash<String,Class<SmartCore::Schema::Plugins::Abstract>>]
|
|
47
|
+
#
|
|
48
|
+
# @api private
|
|
49
|
+
# @since 0.12.0
|
|
50
|
+
def loaded
|
|
51
|
+
@access_lock.read_sync { loaded_plugins }
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# @param block [Block]
|
|
55
|
+
# @return [Enumerable]
|
|
56
|
+
#
|
|
57
|
+
# @api private
|
|
58
|
+
# @since 0.12.0
|
|
59
|
+
def each(&block)
|
|
60
|
+
@access_lock.read_sync { iterate(&block) }
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
private
|
|
64
|
+
|
|
65
|
+
# @return [Hash]
|
|
66
|
+
#
|
|
67
|
+
# @api private
|
|
68
|
+
# @since 0.12.0
|
|
69
|
+
attr_reader :plugin_set
|
|
70
|
+
|
|
71
|
+
# @return [Mutex]
|
|
72
|
+
#
|
|
73
|
+
# @api private
|
|
74
|
+
# @since 0.12.0
|
|
75
|
+
attr_reader :access_lock
|
|
76
|
+
|
|
77
|
+
# @return [Array<String>]
|
|
78
|
+
#
|
|
79
|
+
# @api private
|
|
80
|
+
# @since 0.12.0
|
|
81
|
+
def plugin_names
|
|
82
|
+
plugin_set.keys
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# @param block [Block]
|
|
86
|
+
# @return [Enumerable]
|
|
87
|
+
#
|
|
88
|
+
# @api private
|
|
89
|
+
# @since 0.12.0
|
|
90
|
+
def iterate(&block)
|
|
91
|
+
block_given? ? plugin_set.each_pair(&block) : plugin_set.each_pair
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# @param plugin_name [String]
|
|
95
|
+
# @return [Boolean]
|
|
96
|
+
#
|
|
97
|
+
# @api private
|
|
98
|
+
# @since 0.12.0
|
|
99
|
+
def registered?(plugin_name)
|
|
100
|
+
plugin_set.key?(plugin_name)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# @return [Array<SmartCore::Schema::Plugins::Abstract>]
|
|
104
|
+
#
|
|
105
|
+
# @api private
|
|
106
|
+
# @since 0.12.0
|
|
107
|
+
def loaded_plugins
|
|
108
|
+
plugin_set.select { |_plugin_name, plugin_module| plugin_module.loaded? }
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# @param plugin_name [Symbol, String]
|
|
112
|
+
# @param plugin_module [SmartCore::Schema::Plugins::Abstract]
|
|
113
|
+
# @return [void]
|
|
114
|
+
#
|
|
115
|
+
# @raise [SmartCore::Schema::AlreadyRegisteredPluginError]
|
|
116
|
+
#
|
|
117
|
+
# @api private
|
|
118
|
+
# @since 0.12.0
|
|
119
|
+
def apply(plugin_name, plugin_module)
|
|
120
|
+
plugin_name = indifferently_accessible_plugin_name(plugin_name)
|
|
121
|
+
|
|
122
|
+
if registered?(plugin_name)
|
|
123
|
+
raise(SmartCore::Schema::AlreadyRegisteredPluginError, <<~ERROR_MESSAGE)
|
|
124
|
+
#{plugin_name} plugin already exists
|
|
125
|
+
ERROR_MESSAGE
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
plugin_set[plugin_name] = plugin_module
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
# @param plugin_name [Symbol, String]
|
|
132
|
+
# @return [SmartCore::Schema::Plugins::Abstract]
|
|
133
|
+
#
|
|
134
|
+
# @raise [SmartCore::Schema::UnregisteredPluginError]
|
|
135
|
+
#
|
|
136
|
+
# @api private
|
|
137
|
+
# @since 0.12.0
|
|
138
|
+
def fetch(plugin_name)
|
|
139
|
+
plugin_name = indifferently_accessible_plugin_name(plugin_name)
|
|
140
|
+
|
|
141
|
+
unless registered?(plugin_name)
|
|
142
|
+
raise(SmartCore::Schema::UnregisteredPluginError, <<~ERROR_MESSAGE)
|
|
143
|
+
#{plugin_name} plugin is not registered
|
|
144
|
+
ERROR_MESSAGE
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
plugin_set[plugin_name]
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
# @param key [Symbol, String]
|
|
151
|
+
# @return [String]
|
|
152
|
+
#
|
|
153
|
+
# @api private
|
|
154
|
+
# @since 0.12.0
|
|
155
|
+
def indifferently_accessible_plugin_name(plugin_name)
|
|
156
|
+
plugin_name.to_s
|
|
157
|
+
end
|
|
158
|
+
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# @api private
|
|
4
|
+
# @since 0.12.0
|
|
5
|
+
module SmartCore::Schema::Plugins::RegistryInterface
|
|
6
|
+
class << self
|
|
7
|
+
# @param base_module [Class, Module]
|
|
8
|
+
# @return [void]
|
|
9
|
+
#
|
|
10
|
+
# @api private
|
|
11
|
+
# @since 0.12.0
|
|
12
|
+
def extended(base_module)
|
|
13
|
+
base_module.instance_variable_set(
|
|
14
|
+
:@plugin_registry, SmartCore::Schema::Plugins::Registry.new
|
|
15
|
+
)
|
|
16
|
+
base_module.instance_variable_set(
|
|
17
|
+
:@access_lock, SmartCore::Engine::ReadWriteLock.new
|
|
18
|
+
)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# @param plugin_name [Symbol, String]
|
|
23
|
+
# @return [void]
|
|
24
|
+
#
|
|
25
|
+
# @api public
|
|
26
|
+
# @since 0.12.0
|
|
27
|
+
def load(plugin_name)
|
|
28
|
+
@access_lock.read_sync { plugin_registry[plugin_name].load! }
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# @return [Array<String>]
|
|
32
|
+
#
|
|
33
|
+
# @api public
|
|
34
|
+
# @since 0.12.0
|
|
35
|
+
def loaded_plugins
|
|
36
|
+
@access_lock.read_sync { plugin_registry.loaded.keys }
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# @return [Array<String>]
|
|
40
|
+
#
|
|
41
|
+
# @api public
|
|
42
|
+
# @since 0.12.0
|
|
43
|
+
def names
|
|
44
|
+
@access_lock.read_sync { plugin_registry.names }
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# @param plugin_name [Symbol, String]
|
|
48
|
+
# @return [void]
|
|
49
|
+
#
|
|
50
|
+
# @api private
|
|
51
|
+
# @since 0.12.0
|
|
52
|
+
def register_plugin(plugin_name, plugin_module)
|
|
53
|
+
@access_lock.write_sync { plugin_registry[plugin_name] = plugin_module }
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
private
|
|
57
|
+
|
|
58
|
+
# @return [SmartCore::Schema::Plugins::Registry]
|
|
59
|
+
#
|
|
60
|
+
# @api private
|
|
61
|
+
# @since 0.12.0
|
|
62
|
+
attr_reader :plugin_registry
|
|
63
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# @api private
|
|
4
|
+
# @since 0.12.0
|
|
5
|
+
module SmartCore::Schema::Plugins
|
|
6
|
+
require_relative 'plugins/abstract'
|
|
7
|
+
require_relative 'plugins/registry'
|
|
8
|
+
require_relative 'plugins/registry_interface'
|
|
9
|
+
require_relative 'plugins/access_mixin'
|
|
10
|
+
require_relative 'plugins/dry_types'
|
|
11
|
+
|
|
12
|
+
# @since 0.12.0
|
|
13
|
+
extend SmartCore::Schema::Plugins::RegistryInterface
|
|
14
|
+
|
|
15
|
+
# @since 0.12.0
|
|
16
|
+
register_plugin('dry_types', SmartCore::Schema::Plugins::DryTypes)
|
|
17
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# @api private
|
|
4
|
+
# @since 0.1.0
|
|
5
|
+
# @version 0.3.0
|
|
6
|
+
class SmartCore::Schema::Result
|
|
7
|
+
# @return [Hash<String,Any>]
|
|
8
|
+
#
|
|
9
|
+
# @api public
|
|
10
|
+
# @since 0.1.0
|
|
11
|
+
attr_reader :source
|
|
12
|
+
|
|
13
|
+
# @return [Hash<String,Array<Symbol>>]
|
|
14
|
+
#
|
|
15
|
+
# @api public
|
|
16
|
+
# @since 0.1.0
|
|
17
|
+
attr_reader :errors
|
|
18
|
+
|
|
19
|
+
# @return [Set<String>]
|
|
20
|
+
#
|
|
21
|
+
# @api public
|
|
22
|
+
# @since 0.1.0
|
|
23
|
+
attr_reader :extra_keys
|
|
24
|
+
|
|
25
|
+
# @return [Set<String>]
|
|
26
|
+
#
|
|
27
|
+
# @api public
|
|
28
|
+
# @since 0.3.0
|
|
29
|
+
attr_reader :spread_keys
|
|
30
|
+
|
|
31
|
+
# @param source [Hash<String|Symbol,Any>]
|
|
32
|
+
# @param errors [Hash<String,Array<Symbol>]
|
|
33
|
+
# @param extra_keys [Set<String>]
|
|
34
|
+
# @param spread_keys [Set<String>]
|
|
35
|
+
# @return [void]
|
|
36
|
+
#
|
|
37
|
+
# @api private
|
|
38
|
+
# @since 0.1.0
|
|
39
|
+
# @version 0.3.0
|
|
40
|
+
def initialize(source, errors, extra_keys, spread_keys)
|
|
41
|
+
@source = source
|
|
42
|
+
@errors = errors
|
|
43
|
+
@extra_keys = extra_keys
|
|
44
|
+
@spread_keys = spread_keys
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# @return [Boolean]
|
|
48
|
+
#
|
|
49
|
+
# @api public
|
|
50
|
+
# @since 0.1.0
|
|
51
|
+
def success?
|
|
52
|
+
errors.empty? && extra_keys.empty?
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# @return [Boolean]
|
|
56
|
+
#
|
|
57
|
+
# @api public
|
|
58
|
+
# @since 0.1.0
|
|
59
|
+
def failure?
|
|
60
|
+
errors.any? || extra_keys.any?
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# @abstract
|
|
4
|
+
# @api private
|
|
5
|
+
# @since 0.12.0
|
|
6
|
+
class SmartCore::Schema::TypeSystem::Interop::AbstractFactory
|
|
7
|
+
class << self
|
|
8
|
+
# @param type [Any]
|
|
9
|
+
# @return [SmartCore::Schema::TypeSystem::Interop]
|
|
10
|
+
#
|
|
11
|
+
# @api private
|
|
12
|
+
# @since 0.12.0
|
|
13
|
+
def create(type)
|
|
14
|
+
prevent_incompatible_type!(type)
|
|
15
|
+
|
|
16
|
+
identifier = build_identifier(type)
|
|
17
|
+
valid_op = build_valid_operation(type)
|
|
18
|
+
validate_op = build_validate_operation(type)
|
|
19
|
+
cast_op = build_cast_operation(type)
|
|
20
|
+
|
|
21
|
+
build_interop(identifier, valid_op, validate_op, cast_op)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# @return [Any]
|
|
25
|
+
#
|
|
26
|
+
# @api private
|
|
27
|
+
# @since 0.12.0
|
|
28
|
+
def generic_type_object; end
|
|
29
|
+
|
|
30
|
+
# @param type [Any]
|
|
31
|
+
# @return [String]
|
|
32
|
+
#
|
|
33
|
+
# @api private
|
|
34
|
+
# @since 0.5.1
|
|
35
|
+
def build_identifier(type); end
|
|
36
|
+
|
|
37
|
+
# @param type [Any]
|
|
38
|
+
# @return [void]
|
|
39
|
+
#
|
|
40
|
+
# @raise [SmartCore::Schema::IncorrectTypeObjectError]
|
|
41
|
+
#
|
|
42
|
+
# @api private
|
|
43
|
+
# @since 0.12.0
|
|
44
|
+
def prevent_incompatible_type!(type); end
|
|
45
|
+
|
|
46
|
+
# @return [Class]
|
|
47
|
+
#
|
|
48
|
+
# @api private
|
|
49
|
+
# @since 0.12.1
|
|
50
|
+
def primitive_type_class; end
|
|
51
|
+
|
|
52
|
+
# @return [Any]
|
|
53
|
+
#
|
|
54
|
+
# @api private
|
|
55
|
+
# @since 0.12.1
|
|
56
|
+
def hash_type_object_for_nested_schemas; end
|
|
57
|
+
|
|
58
|
+
private
|
|
59
|
+
|
|
60
|
+
# @param type [Any]
|
|
61
|
+
# @return [SmartCore::Schema::TypeSystem::Interop::Operation]
|
|
62
|
+
#
|
|
63
|
+
# @api private
|
|
64
|
+
# @since 0.12.0
|
|
65
|
+
def build_valid_operation(type); end
|
|
66
|
+
|
|
67
|
+
# @param type [Any]
|
|
68
|
+
# @return [SmartCore::Schema::TypeSystem::Interop::Operation]
|
|
69
|
+
#
|
|
70
|
+
# @api private
|
|
71
|
+
# @since 0.12.0
|
|
72
|
+
def build_validate_operation(type); end
|
|
73
|
+
|
|
74
|
+
# @param type [Any]
|
|
75
|
+
# @return [SmartCore::Schema::TypeSystem::Interop::Operation]
|
|
76
|
+
#
|
|
77
|
+
# @api private
|
|
78
|
+
# @since 0.12.0
|
|
79
|
+
def build_cast_operation(type); end
|
|
80
|
+
|
|
81
|
+
# @param identifier [String]
|
|
82
|
+
# @param valid_op [SmartCore::Schema::TypeSystem::Interop::Operation]
|
|
83
|
+
# @param validate_op [SmartCore::Schema::TypeSystem::Interop::Operation]
|
|
84
|
+
# @param cast_op [SmartCore::Schema::TypeSystem::Interop::Operation]
|
|
85
|
+
# @return [SmartCore::Schema::TypeSystem::Interop]
|
|
86
|
+
#
|
|
87
|
+
# @api private
|
|
88
|
+
# @since 0.12.0
|
|
89
|
+
# @version 0.5.1
|
|
90
|
+
def build_interop(identifier, valid_op, validate_op, cast_op); end
|
|
91
|
+
end
|
|
92
|
+
end
|