
Research
NPM targeted by malware campaign mimicking familiar library names
Socket uncovered npm malware campaign mimicking popular Node.js libraries and packages from other ecosystems; packages steal data and execute remote code.
SmartCore::Schema
is a schema validator for Hash
-like data structures (Array
-like - coming soon) in declarative DSL-powered style.
Provides convenient and concise DSL to define complex schemas in easiest way and public validation interface to achieve a comfortable work with detailed validation result.
Supports nested structures, type validation (via smart_types
), required- and optional- schema keys, strict and non-strict schemas, schema value presence validation, schema inheritance (soon), schema extending (soon) and schema composition (soon).
Works in predicate style and in OOP/Monadic result object style. Enjoy :)
gem 'smart_schema'
bundle install
# --- or ---
gem install smart_schema
require 'smart_core/schema'
required
and optional
;type
;nil
control: filled
;do ... end
;smart_types
gem;strict!
, non_strict!
, schema(:strict)
, schema(:non_strict)
;:strict
is used by default (in first schema
invokation);class MySchema < SmartCore::Schema
# you can mark strict mode in root schema here:
#
# non_strict!
#
# -- or --
#
# strict!
schema do # or here with `schema(:strict)` (default in first time) or `schema(:non_strict)`
required(:key) do
# inherits `:strict`
optional(:data).type(:string).filled
optional(:value).type(:numeric)
required(:name).type(:string)
required(:nested) do
# inherits `:strict`
optional(:version).filled
end
optional(:another_nested) do
non_strict! # marks current nested schema as `:non_strict`
end
end
required(:another_key).filled
end
end
# you can open already defined schema and continue schema definitioning:
schema do
required(:third_key).filled.type(:string)
end
# you can redefine strict behavior of already defined schema:
schema(:non_strict) do
# ...
end
# -- or --
schema do
non_strict!
end
# -- or --
non_strict!
# you can redefine nested schema behavior:
schema do
optional(:another_nested) do
strict! # change from :non_strict to :strict
end
end
MySchema.new.valid?({
key: {
data: '5',
value: 1,
name: 'D@iVeR'
nested: {}
}
another_key: true
}) # => true
MySchema.new.valid?({
key: {
data: nil,
value: 1,
name: 'D@iVeR'
nested: {}
}
}) # => false (missing :another_key, key->data is not filled)
result = MySchema.new.validate(
key: { data: nil, value: '1', name: 'D@iVeR' },
another_key: nil,
third_key: 'test'
)
# => outputs:
# #<SmartCore::Schema::Result:0x00007ffcd8926990
# @errors={"key.data"=>[:non_filled], "key.value"=>[:invalid_type], "key.nested"=>[:required_key_not_found], "another_key"=>[:non_filled], "third_key"=>[:extra_key]},
# @extra_keys=#<Set: {"third_key"}>,
# @spread_keys=#<Set: {}>, (coming soon (spread keys of non-strict schemas))
# @source={:key=>{:data=>nil, :value=>"1", :name=>"D@iVeR"}, :another_key=>nil, :third_key=>"test"}>
result.success? # => false
result.spread_keys # => <Set: {}> (coming soon (spread keys of non-strict schemas))
result.extra_keys # => <Set: {"third_key"}>
result.errors # =>
{
"key.data"=>[:non_filled],
"key.value"=>[:invalid_type],
"key.nested"=>[:required_key_not_found],
"another_key"=>[:non_filled],
"third_key"=>[:extra_key]
}
Possible errors:
:non_filled
(existing key has nil value);:invalid_type
(existing key has invalid type);:required_key_not_found
(required key does not exist);:extra_key
(concrete key does not exist in schema);Array
-like data structures;GitHub Actions
(CI);Array
-type in schema definition;required(:key).schema(SchemaClass)
) (compose_with(AnotherSchema)
);if(:_key_)
rule);smart_type-system
integration;Struct
, OpenStruct
s, custom Object
s and etc);bundle exec rake rspec
bundle exec rake rubocop
bundle exec rake rubocop -A
git checkout -b feature/my-new-feature
)git commit -am '[feature_context] Add some feature'
)git push origin feature/my-new-feature
)Released under MIT License.
FAQs
Unknown package
We found that smart_schema demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Socket uncovered npm malware campaign mimicking popular Node.js libraries and packages from other ecosystems; packages steal data and execute remote code.
Research
Socket's research uncovers three dangerous Go modules that contain obfuscated disk-wiping malware, threatening complete data loss.
Research
Socket uncovers malicious packages on PyPI using Gmail's SMTP protocol for command and control (C2) to exfiltrate data and execute commands.