Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cap32/skeeler
🎩 Writing schema magically
https://github.com/cap32/skeeler
autovivification browser javascript json keywords magic nodejs schema type validation
Last synced: about 1 month ago
JSON representation
🎩 Writing schema magically
- Host: GitHub
- URL: https://github.com/cap32/skeeler
- Owner: Cap32
- License: mit
- Created: 2018-01-05T11:00:24.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-02-04T13:46:53.000Z (almost 7 years ago)
- Last Synced: 2024-11-23T22:03:11.103Z (about 1 month ago)
- Topics: autovivification, browser, javascript, json, keywords, magic, nodejs, schema, type, validation
- Language: JavaScript
- Homepage:
- Size: 192 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# skeeler
[![Build Status](https://travis-ci.org/Cap32/skeeler.svg?branch=master)](https://travis-ci.org/Cap32/skeeler)
[![Coverage Status](https://coveralls.io/repos/github/Cap32/skeeler/badge.svg?branch=master)](https://coveralls.io/github/Cap32/skeeler?branch=master)Writing schema magically
The name is somewhat of a poor choice, but it was available on [npm](https://www.npmjs.com/package/skeeler).
## Simple Example
```js
import Skeeler from 'skeeler';
import SkeelerJSONSchemaDraft6 from 'skeeler-json-schema-draft-6';
import SkeelerMongoose from 'skeeler-mongoose';const types = Skeeler.use('json', new SkeelerJSONSchemaDraft6())
.use('mongoose', new SkeelerMongoose())
.getKeywords();const mySkeeler = new Skeeler({
foo: types.string.required.unique,
bar: types.number.index.exclusiveMinimum(0),
baz: types.objectId.required,
qux: types.array(types.string),
});const jsonSchema = mySkeeler.export('json');
const mongooseSchema = mySkeeler.export('mongoose');export { jsonSchema, mongooseSchema };
```### Equals to JSON Schema v6
```js
export const jsonSchema = {
properties: {
foo: {
type: 'string',
},
bar: {
type: 'number',
exclusiveMinimum: 0,
},
baz: {},
qux: {
type: 'array',
items: {
type: 'string',
},
},
},
required: ['foo', 'baz'],
};
```### Equals to Mongoose Schema
```js
export const mongooseSchema = new Mongoose.Schema({
foo: {
type: String,
required: true,
unique: true,
},
bar: {
type: Number,
index: true,
},
baz: {
type: Mongoose.Types.ObjectId,
required: true,
},
qux: [
{
type: String,
},
],
});
```## Complex Example
```js
import Skeeler from 'skeeler';
import SkeelerJSONSchemaDraft6 from 'skeeler-json-schema-draft-6';
import SkeelerMongoose from 'skeeler-mongoose';const types = Skeeler.use('json', new SkeelerJSONSchemaDraft6())
.use('mongoose', new SkeelerMongoose())
.getKeywords();const mySkeeler = new Skeeler({
foo: types.string.required.unique,
bar: types.number.index,
baz: types.objectId.required,
qux: types.anyOf([
types.object({
quux: types.number.exclusiveMinimum(0),
corge: types.string,
}),
types.string.enum(['grault', 'garply']),
types.boolean,
]),
waldo: types.anyOf([types.array(types.string), types.string]).default([]),
});const jsonSchema = mySkeeler.export('json');
const mongooseSchema = mySkeeler.export('mongoose', { timestamps: true });
mongooseSchema.index({ foo: 'text', baz: 'text' });export { jsonSchema, mongooseSchema };
```## Related Projects
* [skeeler-json-schema-draft-6](https://github.com/Cap32/skeeler-json-schema-draft-6)
* [skeeler-mongoose](https://github.com/Cap32/skeeler-mongoose)## License
MIT