Skip to content

Commit

Permalink
Merge pull request #74 from xpepermint/master
Browse files Browse the repository at this point in the history
Add createModelClass model to core package
  • Loading branch information
xpepermint authored Sep 27, 2019
2 parents 91ec097 + 5915b44 commit aabfeed
Show file tree
Hide file tree
Showing 26 changed files with 258 additions and 109 deletions.
50 changes: 35 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,37 @@ graphql(schema, '{ hello }', root).then((response) => {

## API

### Model Class
### @rawmodel/core

This class is provided by the `@rawmodel/core` package.
**createModelClass(config)**

> Create the Model class from a list of property definitions.
| Option | Type | Required | Default | Description
|--------|------|----------|---------|------------
| config.$.name | String | Yes | - | Property name.
| config.$.prop.set | Function | No | - | Custom setter.
| config.$.prop.get | Function | No | - | Custom getter.
| config.$.prop.parse | Parser | No | - | Data type parser (see supported types).
| config.$.prop.defaultValue | Any | No | - | Prop default value.
| config.$.prop.fakeValue | Any | No | - | Prop fake value.
| config.$.prop.emptyValue | Any | No | - | Prop empty value.
| config.$.prop.validate | Array | No | - | List of validator recipes.
| config.$.prop.handle | Array | No | - | List of error handler recipes.
| config.$.prop.populatable | String[] | No | - | List of strategies for populating the property value.
| config.$.prop.serializable | String[] | No | - | List of strategies for serializing the property value.
| config.$.prop.enumerable | Boolean | No | true | Indicates that the property is enumerable.

```ts
const Model = createModelClass([
{
name: 'name',
prop: {
defaultValue: 'John Smith',
},
},
]);
```

**Model(data, config)**

Expand Down Expand Up @@ -645,10 +673,6 @@ try {
}
```

### Prop Class

This class is provided by the `@rawmodel/core` package.

**Prop(config)**

> A model property.
Expand Down Expand Up @@ -784,17 +808,14 @@ This class is provided by the `@rawmodel/core` package.

> Validates the `value` and populates the property with error.
### Schema Utils

This methods are provided by the `@rawmodel/schema` package.
### @rawmodel/schema

**createModelClass(recipe):Class**

> Returns a new generic model class build from the provided schema `recipe`.
| Option | Type | Required | Default | Description
|--------|------|----------|---------|------------
| recipe.context | Any | No | - | Arbitrary context data.
| recipe.getters | Object | No | - | Hash of getter functions which return a resolver.
| recipe.setters | Object | No | - | Hash of setters functions which return a resolver.
| recipe.defaultValues | Object | No | - | Hash of default value functions which return a resolver or static values.
Expand Down Expand Up @@ -826,7 +847,6 @@ This methods are provided by the `@rawmodel/schema` package.

```ts
const Model = createModelClass({
context: {},
getters: {
customGetter(options: any) { // custom getter function which returns a resolver
return function(v: any) { return v; } // context aware resolver
Expand Down Expand Up @@ -878,9 +898,9 @@ const Model = createModelClass({
});
```
### Available Parsers
### @rawmodel/parsers
Parsers are provided by the `@rawmodel/parsers` package. Note that every model can be used as a parser resolver.
**NOTE:** Every model can be used as a parser `resolver`.
**booleanParser()**: Function
Expand Down Expand Up @@ -913,7 +933,7 @@ const recipe = {
> Converts a value to a string.
### Available Validators
### @rawmodel/validators
Please note that the validators do not trigger if no value is present (on `undefined` or `null`). Make sure your custom validators follow the same concept. The exception are validators which verify value presence or absence.
Expand Down Expand Up @@ -1076,7 +1096,7 @@ const recipe = {
|--------|------|----------|---------|------------
| options.version | Integer | No | - | UUID version (1, 2, 3, 4 or 5).
### Available Handlers
### @rawmodel/handlers
**mongoUniquenessHandler(options)**: Function
Expand Down
115 changes: 51 additions & 64 deletions common/config/rush/npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion common/config/rush/version-policies.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"policyName": "patchAll",
"definitionName": "lockStepVersion",
"version": "3.0.0",
"version": "3.1.0",
"nextBump": "patch"
}
]
6 changes: 6 additions & 0 deletions packages/rawmodel-core/CHANGELOG.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{
"name": "@rawmodel/core",
"entries": [
{
"version": "3.1.0",
"tag": "@rawmodel/core_v3.1.0",
"date": "Fri, 27 Sep 2019 22:48:59 GMT",
"comments": {}
},
{
"version": "3.0.0",
"tag": "@rawmodel/core_v2.4.0",
Expand Down
9 changes: 7 additions & 2 deletions packages/rawmodel-core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# Change Log - @rawmodel/core

This log was last generated on Fri, 12 Jul 2019 17:57:56 GMT and should not be manually modified.
This log was last generated on Fri, 27 Sep 2019 22:48:59 GMT and should not be manually modified.

## 2.4.0
## 3.1.0
Fri, 27 Sep 2019 22:48:59 GMT

*Version update only*

## 3.0.0
Fri, 12 Jul 2019 17:57:56 GMT

*Version update only*
Expand Down
Loading

0 comments on commit aabfeed

Please sign in to comment.