A declarative resource-oriented registry for a generic usage.
Resource Registry allows you to define resources and their actions in a declarative way. Leaving the imperative implementation of the business logic behavior to the user. (Using the repository pattern). And allowing to create generic features for the whole catalog of resources at once.
This is very useful to scale big projects codebases in order to implement generic features for the whole catalog or resources.
It uses few basic concepts to construct this registry:
A resource represents the centric part of this library. They should contain and provide all the necessary information to generate features around. This includes Capabilities, Repository, verbs and Entity/DTOs schemas.
An example of a resource:
class GraphqlCapability < T::Struct
extend T::Sig
include ResourceRegistry::Capabilities::CapabilityConfig
sig { override.returns(Symbol) }
def self.key
:void_capability
end
end
ResourceRegistry::Resource.new(
repository_raw: YourRepositoryClass.to_s,
capabilities: {
graphql: GraphqlCapability.new
},
verbs: {
read: ResourceRegistry::Verb.new(
id: verb,
dto_raw: dto_klass.to_s,
schema: read_verb_schema,
return_many: true
)
},
schema: SchemaRegistry::Schema.new(
name: 'employees',
namespace: 'employees',
properties: [
SchemaRegistry::Property.new(
name: 'id',
types: [SchemaRegistry::PropertyType::String],
required: true
),
SchemaRegistry::Property.new(
name: 'fullName',
types: [SchemaRegistry::PropertyType::String],
required: true
)
]
)
)
Gives you access to the whole library using the following API:
registry = ResourceRegistry::Registry.new
# Fetch a resource by its identifier
registry.fetch(:employees)
# Fetch all resources
registry.fetch_rall
- Schema registry for resources, maybe we can infere them from entities
- Relate events to resources actions (CRUD and not CRUD)
Add the following lines in your Gemfile:
gem 'resource_registry', github: 'factorialco/resource-registry'
And run bundle install
Check ash for a similar and much mature approach applied to Elixir apps.