Based on JSON-Schema, ceramic can map simple JSON into domain entities used in the application. It can also validate entities against constraints specified in the schema.
Ceramic also comes with two optional batteries; Ceramic-db, an Object Document Mapper (ODM) and
Ceramic-http-parser, a parser which converts HTTP form data to entities.
All ceramic projects use ES6 Generators instead of callbacks for async. So you’d have to run wth node with the –harmony flag or use regenerator to transpile code to ES5.
Installation
Usage
Virtual Schemas
The beauty of document-based databases is that document structure is not necessarily rigid. We might use a single collection (or table) to store objects with differing schema, some of which may even be user-defined. For example, the Records collection might store objects of type text-posts, video-posts or short-stories.
Ceramic supports this through a concept called virtual-schemas. Virtual-schemas extend a base-schema with additional properties. To identify which virtual-schema to use, the base-schema must define a discriminator.
Objects created from the virtual-schemas will have their constructor set to that defined in the base-schema.
Validation
Ceramic currently does only basic validation.
Type mismatch (eg: schema says age is a number, but got string)
Required fields
Array max length and min length
Whether a property value is an instance of a class (eg: post.author instanceof Author)
Dynamic Schemas (Advanced)
The simplest way to use Ceramic is to load all the schemas while calling ceramic.init(). But some apps might have dozens (or hundreds) of user-defined schemas stored on the disk that need not be preloaded during init() for performance reasons. Ceramic supports dynamic schemas to address this use case.
If Ceramic comes across a schema (or schema name) that it isn’t aware, it tries to call a custom dynamic schema loader function. The schema loader function must be provided in Ceramic’s constructor, and must return a valid schema when invoked.
Must Construct? (Advanced)
Ceramic will not try to construct an object against a schema if ceramic.mustConstruct() returns false.
You can override the default mustConstruct() behavior (which is true), by providing a custom mustConstruct while creating a Ceramic instance.