Skip to content

Commit 07d9fb8

Browse files
authored
Merge pull request #78 from xpepermint/master
Normalization upgrade
2 parents 202b62c + 68b9d2c commit 07d9fb8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+443
-296
lines changed

CONTRIBUTING.md

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ Always fork the repo and create your branch from master. If you've added code th
3737

3838
Please follow the [TypeScript coding guidelines](https://github.com/Microsoft/TypeScript/wiki/Coding-guidelines).
3939

40+
You should prefix all private variables with `_` sign. To prevent accidental name collisions with your code Rawmodel somes prefixes names of public objects with `$` and names of private objects with `$$`. You can find this convention in outer frameworks like [AngularJS](https://docs.angularjs.org/api).
41+
4042
## Release process
4143

4244
The release manager will publish packages to NPM using these commands.

README.md

+51-51
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ import { stringParser } from '@rawmodel/parsers';
7373

7474
class User extends Model {
7575
@prop({
76-
parse: {
76+
parser: {
7777
resolver: stringParser(),
7878
},
7979
})
@@ -102,13 +102,13 @@ class Friend extends Model {
102102

103103
class User extends Model {
104104
@prop({
105-
parse: {
105+
parser: {
106106
resolver: Address,
107107
},
108108
})
109109
public address: Address;
110110
@prop({
111-
parse: {
111+
parser: {
112112
array: true,
113113
resolver: Friend,
114114
},
@@ -162,15 +162,15 @@ A property can have a custom `getter` and a custom `setter`. This function share
162162

163163
```ts
164164
@prop({
165-
get(value) { return value },
166-
set(value) { return value },
165+
getter(value) { return value },
166+
setter(value) { return value },
167167
})
168168
public name: string;
169169
```
170170

171171
### Value Assignments
172172

173-
Model's properties are like properties on a Javascript Object. We can easily assign a value to a property through its setter method (e.g. `model.name = 'value';`). Instead of assigning properties one by one, we can use the `populate()` method as shown below.
173+
Model's properties are like properties of a Javascript Object. We can easily assign a value to a property through its setter method (e.g. `model.name = 'value';`). Instead of assigning properties one by one, we can use the `populate()` method to assign values to multiple enumerable properties.
174174

175175
```ts
176176
model.populate({
@@ -213,7 +213,7 @@ It's encouraged to use the `populate()` method for assigning values unless you k
213213

214214
### Serialization & Filtering
215215

216-
Model provides useful methods for object serialization and filtering. All properties are serializable by default and are thus included in the result object returned by the `serialize()` method. We can customize the output and include or exclude properties for different situations by using serialization strategies.
216+
Model provides useful methods for object serialization and filtering. All enumerable properties are serializable by default and are thus included in the result object returned by the `serialize()` method. We can customize the output and include or exclude properties for different situations by using serialization strategies.
217217

218218
```ts
219219
class User extends Model {
@@ -272,7 +272,7 @@ RawModel provides a simple mechanism for validating properties. All validators s
272272
```ts
273273
class User extends Model {
274274
@prop({
275-
validate: [ // property validation setup
275+
validators: [ // property validation setup
276276
{ // validator recipe
277277
resolver(v) { return !!v }, // [required] validator function
278278
code: 422, // [optional] error code
@@ -295,7 +295,7 @@ RawModel provides a mechanism for handling property-related errors. The logic is
295295
```ts
296296
class User extends Model {
297297
@prop({
298-
handle: [ // property error handling setup
298+
handlers: [ // property error handling setup
299299
{ // handler recipe
300300
resolver(e) { return e.message === 'foo' }, // [required] error resolve function
301301
code: 31000, // [optional] error code
@@ -366,7 +366,7 @@ const schema = {
366366
props: [ // schema properties
367367
{ // property definition
368368
name: 'title', // property name
369-
validate: [
369+
validators: [
370370
{
371371
resolver: 'stringLength', // validator resolver name
372372
code: 30001, // validation error code
@@ -418,14 +418,14 @@ graphql(schema, '{ hello }', root).then((response) => {
418418
| Option | Type | Required | Default | Description
419419
|--------|------|----------|---------|------------
420420
| config.$.name | String | Yes | - | Property name.
421-
| config.$.prop.set | Function | No | - | Custom setter.
422-
| config.$.prop.get | Function | No | - | Custom getter.
423-
| config.$.prop.parse | Parser | No | - | Data type parser (see supported types).
421+
| config.$.prop.setter | Function | No | - | Custom setter.
422+
| config.$.prop.getter | Function | No | - | Custom getter.
423+
| config.$.prop.parser | Parser | No | - | Data type parser (see supported types).
424424
| config.$.prop.defaultValue | Any | No | - | Prop default value.
425425
| config.$.prop.fakeValue | Any | No | - | Prop fake value.
426426
| config.$.prop.emptyValue | Any | No | - | Prop empty value.
427-
| config.$.prop.validate | Array | No | - | List of validator recipes.
428-
| config.$.prop.handle | Array | No | - | List of error handler recipes.
427+
| config.$.prop.validators | Array | No | - | List of validator recipes.
428+
| config.$.prop.handlers | Array | No | - | List of error handler recipes.
429429
| config.$.prop.populatable | String[] | No | - | List of strategies for populating the property value.
430430
| config.$.prop.serializable | String[] | No | - | List of strategies for serializing the property value.
431431
| config.$.prop.enumerable | Boolean | No | true | Indicates that the property is enumerable.
@@ -456,20 +456,20 @@ class User extends Model {
456456
@prop({
457457
set(v) { return v; }, // [optional] custom setter
458458
get(v) { return v; }, // [optional] custom getter
459-
parse: { // [optional] property type casting
459+
parser: { // [optional] property type casting
460460
array: true, // [optional] forces to array conversion when `true`
461461
resolver: User, // [optional] parser function or Model
462462
},
463463
defaultValue: 'Noname', // [optional] property default value (value or function)
464464
fakeValue: 'Noname', // [optional] property fake value (value or function)
465465
emptyValue: '', // [optional] property empty value (value or function)
466-
validate: [ // [optional] value validator recipes
466+
validators: [ // [optional] value validator recipes
467467
{ // validator recipe (check validatable.js for more)
468468
resolver(v) { return !!v; }, // [required] validator resolve function (supports async)
469469
code: 422, // [optional] error code
470470
},
471471
],
472-
handle: [ // [optional] error handling recipies
472+
handlers: [ // [optional] error handling recipies
473473
{ // handler recipe
474474
resolver(e) { return e.message === 'foo'; }, // [required] handler resolve function (supports async)
475475
code: 31000, // [required] error code
@@ -489,14 +489,14 @@ class User extends Model {
489489
490490
| Option | Type | Required | Default | Description
491491
|--------|------|----------|---------|------------
492-
| config.set | Function | No | - | Custom setter.
493-
| config.get | Function | No | - | Custom getter.
494-
| config.parse | Parser | No | - | Data type parser (see supported types).
492+
| config.setter | Function | No | - | Custom setter.
493+
| config.getter | Function | No | - | Custom getter.
494+
| config.parser | Parser | No | - | Data type parser (see supported types).
495495
| config.defaultValue | Any | No | - | Prop default value.
496496
| config.fakeValue | Any | No | - | Prop fake value.
497497
| config.emptyValue | Any | No | - | Prop empty value.
498-
| config.validate | Array | No | - | List of validator recipes.
499-
| config.handle | Array | No | - | List of error handler recipes.
498+
| config.validators | Array | No | - | List of validator recipes.
499+
| config.handlers | Array | No | - | List of error handler recipes.
500500
| config.populatable | String[] | No | - | List of strategies for populating the property value.
501501
| config.serializable | String[] | No | - | List of strategies for serializing the property value.
502502
| config.enumerable | Boolean | No | true | Indicates that the property is enumerable.
@@ -571,6 +571,10 @@ user.flatten(); // -> [{ path, prop, value }, ...]
571571

572572
> Makes each model property not settable.
573573
574+
**Model.prototype.getAncestors()**: Model[]
575+
576+
> Returns a list of all parent model instances.
577+
574578
**Model.prototype.getContext()**: Context
575579

576580
> Returns model context data.
@@ -587,10 +591,6 @@ user.flatten(); // -> [{ path, prop, value }, ...]
587591
|--------|------|----------|---------|------------
588592
| keys | Array | Yes | - | Path to a property (e.g. `['book', 0, 'title']`).
589593

590-
**Model.prototype.getRoot()**: Model
591-
592-
> Returns the first model instance in a tree of models.
593-
594594
**Model.prototype.handle(error, { quiet }): Promise(Model)**
595595

596596
> Tries to handle the `error` against each property handlers and populates the model with possible errors.
@@ -638,7 +638,7 @@ try {
638638
639639
**Model.prototype.populate(data, strategy)**: Model
640640

641-
> Applies data to a model.
641+
> Populates enumerable properties with data.
642642
643643
| Option | Type | Required | Default | Description
644644
|--------|------|----------|---------|------------
@@ -655,7 +655,7 @@ try {
655655
656656
**Model.prototype.serialize(strategy)**: Object
657657

658-
> Converts a model into serialized data object.
658+
> Converts a model into serialized data object. The result will include only enumerable properties.
659659
660660
| Option | Type | Required | Default | Description
661661
|--------|------|----------|---------|------------
@@ -683,14 +683,14 @@ try {
683683
684684
| Option | Type | Required | Default | Description
685685
|--------|------|----------|---------|------------
686-
| config.set | Function | No | - | Custom setter.
687-
| config.get | Function | No | - | Custom getter.
688-
| config.parse | Parser | No | - | Data type parser (see supported types).
686+
| config.setter | Function | No | - | Custom setter.
687+
| config.getter | Function | No | - | Custom getter.
688+
| config.parser | Parser | No | - | Data type parser (see supported types).
689689
| config.defaultValue | Any | No | - | Prop default value.
690690
| config.fakeValue | Any | No | - | Prop fake value.
691691
| config.emptyValue | Any | No | - | Prop empty value.
692-
| config.validate | Array | No | - | List of validator recipes.
693-
| config.handle | Array | No | - | List of error handler recipes.
692+
| config.validators | Array | No | - | List of validator recipes.
693+
| config.handlers | Array | No | - | List of error handler recipes.
694694
| config.populatable | String[] | No | - | List of strategies for populating the property value.
695695
| config.serializable | String[] | No | - | List of strategies for serializing the property value.
696696
| config.enumerable | Boolean | No | true | Indicates that the property is enumerable.
@@ -794,7 +794,7 @@ try {
794794
795795
**Prop.prototype.serialize(strategy)**
796796

797-
> Returns a serialized property value.
797+
> Returns a serialized property value. Note that only enumerable properties are serializable.
798798
799799
| Option | Type | Required | Default | Description
800800
|--------|------|----------|---------|------------
@@ -831,20 +831,20 @@ try {
831831
| recipe.props | Array | No | - | Hash of property definitions.
832832
| recipe.props.$.set | String | No | - | Setter resolver name.
833833
| recipe.props.$.get | String | No | - | Getter resolver name.
834-
| recipe.props.$.parse | Object | No | - | Data type parser recipe.
835-
| recipe.props.$.parse.array | Boolean | No | false | When `true` the input data will automatically be converted to array.
836-
| recipe.props.$.parse.resolver | String | No | - | Parser resolver name
834+
| recipe.props.$.parser | Object | No | - | Data type parser recipe.
835+
| recipe.props.$.parser.array | Boolean | No | false | When `true` the input data will automatically be converted to array.
836+
| recipe.props.$.parser.resolver | String | No | - | Parser resolver name
837837
| recipe.props.$.defaultValue | Any | No | - | Default value resolver name or a value.
838838
| recipe.props.$.fakeValue | Any | No | - | Fake value resolver name or a value.
839839
| recipe.props.$.emptyValue | Any | No | - | Empty value resolver name or a value.
840-
| recipe.props.$.validate | Array | No | - | List of validator recipes.
841-
| recipe.props.$.validate.code | Integer | Yes | - | Validator error code.
842-
| recipe.props.$.validate.resolver | String | Yes | - | Validator resolver name.
843-
| recipe.props.$.validate.options | Object | No | - | Validator resolver arguments.
844-
| recipe.props.$.handle | Array | No | - | List of error handler recipes.
845-
| recipe.props.$.handle.code | Integer | Yes | - | Handler error code.
846-
| recipe.props.$.handle.resolver | String | Yes | - | Handler resolver name.
847-
| recipe.props.$.handle.options | Object | No | - | Handler resolver arguments.
840+
| recipe.props.$.validators | Array | No | - | List of validator recipes.
841+
| recipe.props.$.validators.code | Integer | Yes | - | Validator error code.
842+
| recipe.props.$.validators.resolver | String | Yes | - | Validator resolver name.
843+
| recipe.props.$.validators.options | Object | No | - | Validator resolver arguments.
844+
| recipe.props.$.handlers | Array | No | - | List of error handler recipes.
845+
| recipe.props.$.handlers.code | Integer | Yes | - | Handler error code.
846+
| recipe.props.$.handlers.resolver | String | Yes | - | Handler resolver name.
847+
| recipe.props.$.handlers.options | Object | No | - | Handler resolver arguments.
848848
| recipe.props.$.populatable | Array | No | - | List of strategies for populating the property value.
849849
| recipe.props.$.serializable | Array | No | - | List of strategies for serializing the property value.
850850
| recipe.props.$.enumerable | Boolean | No | true | Indicates that the property is enumerable.
@@ -879,22 +879,22 @@ const Model = createModelClass({
879879
handlers: {}, // see validators
880880
props: [
881881
name: 'firstName', // property name
882-
get: 'customGetter', // getter name (defined in `getters`)
883-
set: 'customSetter', // setter name (defined in `setters`)
884-
parse: {
882+
getter: 'customGetter', // getter name (defined in `getters`)
883+
setter: 'customSetter', // setter name (defined in `setters`)
884+
parser: {
885885
array: true, // when `true` the input is converted to array
886886
resolver: 'toString', // parser resolver name
887887
},
888888
defaultValue: 'none', // static default value
889889
fakeValue: 'none', // static fake value
890890
emptyValue: '', // static empty value
891-
validate: [
891+
validators: [
892892
{
893893
code: 30001, // validator error code
894894
resolver: 'isPresent', // validator resolver name
895895
},
896896
],
897-
handle: [], // see validators
897+
handlers: [], // see validators
898898
populatable: ['input', 'db'], // populatable strategies
899899
serializable: ['input', 'db'], // serializable strategies
900900
enumerable: true, // property is enumerable

common/config/rush/npm-shrinkwrap.json

+13-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/config/rush/version-policies.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
"policyName": "patchAll",
44
"definitionName": "lockStepVersion",
5-
"version": "3.2.1",
5+
"version": "3.3.0",
66
"nextBump": "patch"
77
}
88
]

packages/rawmodel-core/CHANGELOG.json

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
{
22
"name": "@rawmodel/core",
33
"entries": [
4+
{
5+
"version": "3.3.0",
6+
"tag": "@rawmodel/core_v3.3.0",
7+
"date": "Thu, 03 Oct 2019 15:49:09 GMT",
8+
"comments": {}
9+
},
410
{
511
"version": "3.2.1",
612
"tag": "@rawmodel/core_v3.2.1",

packages/rawmodel-core/CHANGELOG.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Change Log - @rawmodel/core
22

3-
This log was last generated on Sun, 29 Sep 2019 10:22:42 GMT and should not be manually modified.
3+
This log was last generated on Thu, 03 Oct 2019 15:49:09 GMT and should not be manually modified.
4+
5+
## 3.3.0
6+
Thu, 03 Oct 2019 15:49:09 GMT
7+
8+
*Version update only*
49

510
## 3.2.1
611
Sun, 29 Sep 2019 10:22:42 GMT

0 commit comments

Comments
 (0)