objectmodel 4.4.0 → 4.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +8 -8
- package/.eslintrc.json +25 -25
- package/LICENSE +22 -22
- package/README.md +67 -67
- package/build/add-banner.js +13 -13
- package/build/bundle-entry.dev.js +2 -2
- package/build/bundle-entry.js +11 -11
- package/dist/object-model.cjs +84 -84
- package/dist/object-model.js +84 -84
- package/dist/object-model.js.map +1 -1
- package/dist/object-model.min.js +2 -2
- package/dist/object-model.min.js.map +1 -1
- package/index.html +2 -2
- package/package.json +70 -70
- package/rollup.config.js +13 -13
- package/src/helpers.js +43 -43
- package/src/list-model.js +43 -43
- package/src/object-model.js +1 -1
- package/test/array-model.spec.cjs +291 -291
- package/test/basic-model.spec.cjs +263 -263
- package/test/bench/array.html +51 -51
- package/test/bench/bench-lib.js +49 -49
- package/test/bench/map-no-cast.html +53 -53
- package/test/bench/map-set.html +52 -52
- package/test/bench/map.html +51 -51
- package/test/bench/object-models.html +87 -87
- package/test/index.cjs +13 -13
- package/test/map-model.spec.cjs +224 -224
- package/test/model.spec.cjs +30 -30
- package/test/object-model.spec.cjs +23 -0
- package/test/set-model.spec.cjs +213 -213
- package/test/umd.html +25 -25
- package/.travis.yml +0 -3
package/.eslintignore
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
docs/examples/common.js
|
|
2
|
-
dist
|
|
3
|
-
test/lib
|
|
4
|
-
docs/**/lib
|
|
5
|
-
docs/v1
|
|
6
|
-
docs/v2
|
|
7
|
-
docs/node_modules
|
|
8
|
-
*.compiled.js
|
|
1
|
+
docs/examples/common.js
|
|
2
|
+
dist
|
|
3
|
+
test/lib
|
|
4
|
+
docs/**/lib
|
|
5
|
+
docs/v1
|
|
6
|
+
docs/v2
|
|
7
|
+
docs/node_modules
|
|
8
|
+
*.compiled.js
|
|
9
9
|
*.html
|
package/.eslintrc.json
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "eslint:recommended",
|
|
3
|
-
"env": {
|
|
4
|
-
"browser": true,
|
|
5
|
-
"node": true,
|
|
6
|
-
"es6": true
|
|
7
|
-
},
|
|
8
|
-
"parserOptions": {
|
|
9
|
-
"ecmaVersion": 2018,
|
|
10
|
-
"sourceType": "module"
|
|
11
|
-
},
|
|
12
|
-
"rules": {
|
|
13
|
-
"indent": [
|
|
14
|
-
"error",
|
|
15
|
-
"tab",
|
|
16
|
-
{
|
|
17
|
-
"SwitchCase": 1
|
|
18
|
-
}
|
|
19
|
-
],
|
|
20
|
-
"no-mixed-spaces-and-tabs": [
|
|
21
|
-
"error",
|
|
22
|
-
"smart-tabs"
|
|
23
|
-
],
|
|
24
|
-
"no-console": "off"
|
|
25
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"extends": "eslint:recommended",
|
|
3
|
+
"env": {
|
|
4
|
+
"browser": true,
|
|
5
|
+
"node": true,
|
|
6
|
+
"es6": true
|
|
7
|
+
},
|
|
8
|
+
"parserOptions": {
|
|
9
|
+
"ecmaVersion": 2018,
|
|
10
|
+
"sourceType": "module"
|
|
11
|
+
},
|
|
12
|
+
"rules": {
|
|
13
|
+
"indent": [
|
|
14
|
+
"error",
|
|
15
|
+
"tab",
|
|
16
|
+
{
|
|
17
|
+
"SwitchCase": 1
|
|
18
|
+
}
|
|
19
|
+
],
|
|
20
|
+
"no-mixed-spaces-and-tabs": [
|
|
21
|
+
"error",
|
|
22
|
+
"smart-tabs"
|
|
23
|
+
],
|
|
24
|
+
"no-console": "off"
|
|
25
|
+
}
|
|
26
26
|
}
|
package/LICENSE
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
Copyright (c) 2015 Sylvain Pollet-Villard
|
|
2
|
-
|
|
3
|
-
Permission is hereby granted, free of charge, to any person
|
|
4
|
-
obtaining a copy of this software and associated documentation
|
|
5
|
-
files (the "Software"), to deal in the Software without
|
|
6
|
-
restriction, including without limitation the rights to use,
|
|
7
|
-
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
-
copies of the Software, and to permit persons to whom the
|
|
9
|
-
Software is furnished to do so, subject to the following
|
|
10
|
-
conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be
|
|
13
|
-
included in all copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
16
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
17
|
-
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
18
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
19
|
-
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
20
|
-
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
21
|
-
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
22
|
-
OTHER DEALINGS IN THE SOFTWARE.
|
|
1
|
+
Copyright (c) 2015 Sylvain Pollet-Villard
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
|
4
|
+
obtaining a copy of this software and associated documentation
|
|
5
|
+
files (the "Software"), to deal in the Software without
|
|
6
|
+
restriction, including without limitation the rights to use,
|
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the
|
|
9
|
+
Software is furnished to do so, subject to the following
|
|
10
|
+
conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be
|
|
13
|
+
included in all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,68 +1,68 @@
|
|
|
1
|
-
<p align="center"><a href="http://objectmodel.js.org" target="_blank"><img width="400" src="http://objectmodel.js.org/docs/res/logo.png"></a></p>
|
|
2
|
-
|
|
3
|
-
<p align="center">Strong Dynamically Typed Object Modeling for JavaScript</p>
|
|
4
|
-
<p align="center">
|
|
5
|
-
<a href="https://www.npmjs.com/package/objectmodel"><img src="https://img.shields.io/npm/dt/objectmodel.svg" alt="Downloads"></a>
|
|
6
|
-
<a href="https://www.npmjs.com/package/objectmodel"><img src="https://img.shields.io/npm/v/objectmodel.svg" alt="Version"></a>
|
|
7
|
-
<a href="https://travis-ci.org/sylvainpolletvillard/ObjectModel"><img src="https://travis-ci.org/sylvainpolletvillard/ObjectModel.svg?branch=master" alt="Status"></a>
|
|
8
|
-
<a href="https://www.npmjs.com/package/objectmodel"><img src="https://img.shields.io/npm/l/objectmodel.svg" alt="License"></a>
|
|
9
|
-
</p>
|
|
10
|
-
|
|
11
|
-
---
|
|
12
|
-
|
|
13
|
-
## What is this library ?
|
|
14
|
-
|
|
15
|
-
ObjectModel intends to bring **strong dynamic type checking** to your web applications. Contrary to static type-checking solutions like [TypeScript] or [Flow], ObjectModel can also validate data at runtime: JSON from the server, form inputs, content from localStorage, external libraries...
|
|
16
|
-
|
|
17
|
-
By leveraging **ES6 Proxies**, this library ensures that your variables always match the model definition and validation constraints you added to them. Thanks to the generated exceptions, it will help you spot potential bugs and save you time spent on debugging. ObjectModel is also very easy to master: *no new language to learn, no new tools, no compilation step, just a minimalist and intuitive API in a plain old JS micro-library*.
|
|
18
|
-
|
|
19
|
-
Validating at runtime also brings many other benefits: you can define your own types, use them in complex model definitions with custom assertions that can even change depending on your application state. Actually it goes much further than just type safety. Go on and see for yourself.
|
|
20
|
-
|
|
21
|
-
## Installation
|
|
22
|
-
Add the library to your project dependencies with NPM:
|
|
23
|
-
```bash
|
|
24
|
-
$ npm install objectmodel
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
or just [download the library from Github][github-releases]
|
|
28
|
-
|
|
29
|
-
## Basic usage example
|
|
30
|
-
|
|
31
|
-
```javascript
|
|
32
|
-
import { ObjectModel } from "objectmodel"
|
|
33
|
-
|
|
34
|
-
const Order = new ObjectModel({
|
|
35
|
-
product: { name: String, quantity: Number },
|
|
36
|
-
orderDate: Date
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
const myOrder = new Order({
|
|
40
|
-
product: { name: "Apple Pie", quantity: 1 },
|
|
41
|
-
orderDate: new Date()
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
myOrder.product.quantity = 2; // no exceptions thrown
|
|
45
|
-
myOrder.product.quantity = false; //try to assign a Boolean
|
|
46
|
-
// ❌ TypeError: expecting product.quantity to be Number, got Boolean false
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
## Documentation
|
|
50
|
-
|
|
51
|
-
For more examples, documentation and questions, please refer to the project website: [objectmodel.js.org][website]
|
|
52
|
-
|
|
53
|
-
## Changelog and Release History
|
|
54
|
-
|
|
55
|
-
Please refer to [Github Releases][github-releases]
|
|
56
|
-
|
|
57
|
-
*Bug reports and pull requests are welcome.*
|
|
58
|
-
|
|
59
|
-
Distributed under the MIT license. See ``LICENSE`` for more information.
|
|
60
|
-
|
|
61
|
-
[website]:http://objectmodel.js.org
|
|
62
|
-
[TypeScript]:https://www.typescriptlang.org/
|
|
63
|
-
[Flow]:https://flowtype.org/
|
|
64
|
-
[github-releases]:https://github.com/sylvainpolletvillard/ObjectModel/releases
|
|
65
|
-
[npm-url]: https://npmjs.org/package/objectmodel
|
|
66
|
-
[npm-image]: https://img.shields.io/npm/v/objectmodel.svg
|
|
67
|
-
[npm-downloads]: https://img.shields.io/npm/dm/objectmodel.svg
|
|
1
|
+
<p align="center"><a href="http://objectmodel.js.org" target="_blank"><img width="400" src="http://objectmodel.js.org/docs/res/logo.png"></a></p>
|
|
2
|
+
|
|
3
|
+
<p align="center">Strong Dynamically Typed Object Modeling for JavaScript</p>
|
|
4
|
+
<p align="center">
|
|
5
|
+
<a href="https://www.npmjs.com/package/objectmodel"><img src="https://img.shields.io/npm/dt/objectmodel.svg" alt="Downloads"></a>
|
|
6
|
+
<a href="https://www.npmjs.com/package/objectmodel"><img src="https://img.shields.io/npm/v/objectmodel.svg" alt="Version"></a>
|
|
7
|
+
<a href="https://travis-ci.org/sylvainpolletvillard/ObjectModel"><img src="https://travis-ci.org/sylvainpolletvillard/ObjectModel.svg?branch=master" alt="Status"></a>
|
|
8
|
+
<a href="https://www.npmjs.com/package/objectmodel"><img src="https://img.shields.io/npm/l/objectmodel.svg" alt="License"></a>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## What is this library ?
|
|
14
|
+
|
|
15
|
+
ObjectModel intends to bring **strong dynamic type checking** to your web applications. Contrary to static type-checking solutions like [TypeScript] or [Flow], ObjectModel can also validate data at runtime: JSON from the server, form inputs, content from localStorage, external libraries...
|
|
16
|
+
|
|
17
|
+
By leveraging **ES6 Proxies**, this library ensures that your variables always match the model definition and validation constraints you added to them. Thanks to the generated exceptions, it will help you spot potential bugs and save you time spent on debugging. ObjectModel is also very easy to master: *no new language to learn, no new tools, no compilation step, just a minimalist and intuitive API in a plain old JS micro-library*.
|
|
18
|
+
|
|
19
|
+
Validating at runtime also brings many other benefits: you can define your own types, use them in complex model definitions with custom assertions that can even change depending on your application state. Actually it goes much further than just type safety. Go on and see for yourself.
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
Add the library to your project dependencies with NPM:
|
|
23
|
+
```bash
|
|
24
|
+
$ npm install objectmodel
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
or just [download the library from Github][github-releases]
|
|
28
|
+
|
|
29
|
+
## Basic usage example
|
|
30
|
+
|
|
31
|
+
```javascript
|
|
32
|
+
import { ObjectModel } from "objectmodel"
|
|
33
|
+
|
|
34
|
+
const Order = new ObjectModel({
|
|
35
|
+
product: { name: String, quantity: Number },
|
|
36
|
+
orderDate: Date
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const myOrder = new Order({
|
|
40
|
+
product: { name: "Apple Pie", quantity: 1 },
|
|
41
|
+
orderDate: new Date()
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
myOrder.product.quantity = 2; // no exceptions thrown
|
|
45
|
+
myOrder.product.quantity = false; //try to assign a Boolean
|
|
46
|
+
// ❌ TypeError: expecting product.quantity to be Number, got Boolean false
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Documentation
|
|
50
|
+
|
|
51
|
+
For more examples, documentation and questions, please refer to the project website: [objectmodel.js.org][website]
|
|
52
|
+
|
|
53
|
+
## Changelog and Release History
|
|
54
|
+
|
|
55
|
+
Please refer to [Github Releases][github-releases]
|
|
56
|
+
|
|
57
|
+
*Bug reports and pull requests are welcome.*
|
|
58
|
+
|
|
59
|
+
Distributed under the MIT license. See ``LICENSE`` for more information.
|
|
60
|
+
|
|
61
|
+
[website]:http://objectmodel.js.org
|
|
62
|
+
[TypeScript]:https://www.typescriptlang.org/
|
|
63
|
+
[Flow]:https://flowtype.org/
|
|
64
|
+
[github-releases]:https://github.com/sylvainpolletvillard/ObjectModel/releases
|
|
65
|
+
[npm-url]: https://npmjs.org/package/objectmodel
|
|
66
|
+
[npm-image]: https://img.shields.io/npm/v/objectmodel.svg
|
|
67
|
+
[npm-downloads]: https://img.shields.io/npm/dm/objectmodel.svg
|
|
68
68
|
[license-badge]:https://img.shields.io/badge/license-MIT-blue.svg
|
package/build/add-banner.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import pkg from '../package.json' assert { type: 'json' };
|
|
3
|
-
|
|
4
|
-
const banner = `// ObjectModel v${pkg.version} - ${pkg.homepage}
|
|
5
|
-
// ${pkg.license} License - ${pkg.author}`;
|
|
6
|
-
|
|
7
|
-
const paths = [
|
|
8
|
-
"./dist/object-model.js",
|
|
9
|
-
"./dist/object-model.min.js"
|
|
10
|
-
]
|
|
11
|
-
|
|
12
|
-
paths.forEach(path => {
|
|
13
|
-
fs.writeFileSync(path, banner + '\n' + fs.readFileSync(path, 'utf8'))
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import pkg from '../package.json' assert { type: 'json' };
|
|
3
|
+
|
|
4
|
+
const banner = `// ObjectModel v${pkg.version} - ${pkg.homepage}
|
|
5
|
+
// ${pkg.license} License - ${pkg.author}`;
|
|
6
|
+
|
|
7
|
+
const paths = [
|
|
8
|
+
"./dist/object-model.js",
|
|
9
|
+
"./dist/object-model.min.js"
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
paths.forEach(path => {
|
|
13
|
+
fs.writeFileSync(path, banner + '\n' + fs.readFileSync(path, 'utf8'))
|
|
14
14
|
})
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "../src/devtool-formatter"
|
|
2
|
-
|
|
1
|
+
import "../src/devtool-formatter"
|
|
2
|
+
|
|
3
3
|
export * from "./bundle-entry"
|
package/build/bundle-entry.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { Model, BasicModel, ObjectModel, ArrayModel, FunctionModel, MapModel, SetModel, Any } from "../src/index"
|
|
2
|
-
|
|
3
|
-
export {
|
|
4
|
-
Model,
|
|
5
|
-
BasicModel,
|
|
6
|
-
ObjectModel,
|
|
7
|
-
ArrayModel,
|
|
8
|
-
FunctionModel,
|
|
9
|
-
MapModel,
|
|
10
|
-
SetModel,
|
|
11
|
-
Any
|
|
1
|
+
import { Model, BasicModel, ObjectModel, ArrayModel, FunctionModel, MapModel, SetModel, Any } from "../src/index"
|
|
2
|
+
|
|
3
|
+
export {
|
|
4
|
+
Model,
|
|
5
|
+
BasicModel,
|
|
6
|
+
ObjectModel,
|
|
7
|
+
ArrayModel,
|
|
8
|
+
FunctionModel,
|
|
9
|
+
MapModel,
|
|
10
|
+
SetModel,
|
|
11
|
+
Any
|
|
12
12
|
}
|
package/dist/object-model.cjs
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
// ObjectModel v4.4.
|
|
1
|
+
// ObjectModel v4.4.2 - http://objectmodel.js.org
|
|
2
2
|
// MIT License - Sylvain Pollet-Villard
|
|
3
|
-
const
|
|
4
|
-
ObjectProto = Object.prototype,
|
|
5
|
-
bettertypeof = x => ObjectProto.toString.call(x).match(/\s([a-zA-Z]+)/)[1],
|
|
6
|
-
getProto = Object.getPrototypeOf,
|
|
7
|
-
setProto = Object.setPrototypeOf,
|
|
8
|
-
|
|
9
|
-
has = (o, prop) => ObjectProto.hasOwnProperty.call(o, prop),
|
|
10
|
-
is = (Constructor, obj) => obj instanceof Constructor,
|
|
11
|
-
isFunction = f => typeof f === "function",
|
|
12
|
-
isObject = o => o && typeof o === "object",
|
|
13
|
-
isString = s => typeof s === "string",
|
|
14
|
-
isPlainObject = o => isObject(o) && getProto(o) === ObjectProto,
|
|
15
|
-
isIterable = x => x && isFunction(x[Symbol.iterator]),
|
|
16
|
-
|
|
17
|
-
proxify = (val, traps) => new Proxy(val, traps),
|
|
18
|
-
|
|
19
|
-
merge = (target, src = {}) => {
|
|
20
|
-
for (let key in src) {
|
|
21
|
-
if (isPlainObject(src[key])) {
|
|
22
|
-
const o = {};
|
|
23
|
-
merge(o, target[key]);
|
|
24
|
-
merge(o, src[key]);
|
|
25
|
-
target[key] = o;
|
|
26
|
-
} else {
|
|
27
|
-
target[key] = src[key];
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return target
|
|
31
|
-
},
|
|
32
|
-
|
|
33
|
-
define = (obj, key, value, enumerable = false) => {
|
|
34
|
-
Object.defineProperty(obj, key, { value, enumerable, writable: true, configurable: true });
|
|
35
|
-
},
|
|
36
|
-
|
|
37
|
-
extend = (child, parent, props) => {
|
|
38
|
-
child.prototype = Object.assign(Object.create(parent.prototype, {
|
|
39
|
-
constructor: {
|
|
40
|
-
value: child,
|
|
41
|
-
writable: true,
|
|
42
|
-
configurable: true
|
|
43
|
-
}
|
|
44
|
-
}), props);
|
|
45
|
-
setProto(child, parent);
|
|
3
|
+
const
|
|
4
|
+
ObjectProto = Object.prototype,
|
|
5
|
+
bettertypeof = x => ObjectProto.toString.call(x).match(/\s([a-zA-Z]+)/)[1],
|
|
6
|
+
getProto = Object.getPrototypeOf,
|
|
7
|
+
setProto = Object.setPrototypeOf,
|
|
8
|
+
|
|
9
|
+
has = (o, prop) => ObjectProto.hasOwnProperty.call(o, prop),
|
|
10
|
+
is = (Constructor, obj) => obj instanceof Constructor,
|
|
11
|
+
isFunction = f => typeof f === "function",
|
|
12
|
+
isObject = o => o && typeof o === "object",
|
|
13
|
+
isString = s => typeof s === "string",
|
|
14
|
+
isPlainObject = o => isObject(o) && getProto(o) === ObjectProto,
|
|
15
|
+
isIterable = x => x && isFunction(x[Symbol.iterator]),
|
|
16
|
+
|
|
17
|
+
proxify = (val, traps) => new Proxy(val, traps),
|
|
18
|
+
|
|
19
|
+
merge = (target, src = {}) => {
|
|
20
|
+
for (let key in src) {
|
|
21
|
+
if (isPlainObject(src[key])) {
|
|
22
|
+
const o = {};
|
|
23
|
+
merge(o, target[key]);
|
|
24
|
+
merge(o, src[key]);
|
|
25
|
+
target[key] = o;
|
|
26
|
+
} else {
|
|
27
|
+
target[key] = src[key];
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return target
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
define = (obj, key, value, enumerable = false) => {
|
|
34
|
+
Object.defineProperty(obj, key, { value, enumerable, writable: true, configurable: true });
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
extend = (child, parent, props) => {
|
|
38
|
+
child.prototype = Object.assign(Object.create(parent.prototype, {
|
|
39
|
+
constructor: {
|
|
40
|
+
value: child,
|
|
41
|
+
writable: true,
|
|
42
|
+
configurable: true
|
|
43
|
+
}
|
|
44
|
+
}), props);
|
|
45
|
+
setProto(child, parent);
|
|
46
46
|
};
|
|
47
47
|
|
|
48
48
|
const
|
|
@@ -156,7 +156,7 @@ const
|
|
|
156
156
|
|
|
157
157
|
if (is(Model, def)) {
|
|
158
158
|
if (shouldCast) obj = cast(obj, def);
|
|
159
|
-
def[_check](obj, path, errors, stack.concat(def));
|
|
159
|
+
def[_check](obj, path, errors, stack.concat(def), shouldCast);
|
|
160
160
|
}
|
|
161
161
|
else if (isPlainObject(def)) {
|
|
162
162
|
for (let key in def) {
|
|
@@ -520,45 +520,45 @@ extend(Any.remaining, Any, {
|
|
|
520
520
|
});
|
|
521
521
|
Any[Symbol.iterator] = function* () { yield new Any.remaining(this.definition); };
|
|
522
522
|
|
|
523
|
-
const initListModel = (base, constructor, def, init, clone, mutators, otherTraps) => {
|
|
524
|
-
|
|
525
|
-
return initModel(def, constructor, base, init, model => Object.assign({
|
|
526
|
-
getPrototypeOf: () => model.prototype,
|
|
527
|
-
get(l, key) {
|
|
528
|
-
if (key === _original) return l
|
|
529
|
-
|
|
530
|
-
const val = l[key];
|
|
531
|
-
return isFunction(val) ? proxify(val, {
|
|
532
|
-
apply(fn, ctx, args) {
|
|
533
|
-
if (has(mutators, key)) {
|
|
534
|
-
// indexes of arguments to check def + cast
|
|
535
|
-
const [begin, end = args.length - 1, getArgDef] = mutators[key];
|
|
536
|
-
for (let i = begin; i <= end; i++) {
|
|
537
|
-
const argDef = getArgDef ? getArgDef(i) : model.definition;
|
|
538
|
-
args[i] = checkDefinition(
|
|
539
|
-
args[i],
|
|
540
|
-
argDef,
|
|
541
|
-
`${base.name}.${key} arguments[${i}]`,
|
|
542
|
-
model.errors,
|
|
543
|
-
[],
|
|
544
|
-
true
|
|
545
|
-
);
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
if (model.assertions.length > 0) {
|
|
549
|
-
const testingClone = clone(l);
|
|
550
|
-
fn.apply(testingClone, args);
|
|
551
|
-
checkAssertions(testingClone, model, `after ${key} mutation`);
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
unstackErrors(model);
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
return fn.apply(l, args)
|
|
558
|
-
}
|
|
559
|
-
}) : val
|
|
560
|
-
}
|
|
561
|
-
}, otherTraps))
|
|
523
|
+
const initListModel = (base, constructor, def, init, clone, mutators, otherTraps) => {
|
|
524
|
+
|
|
525
|
+
return initModel(def, constructor, base, init, model => Object.assign({
|
|
526
|
+
getPrototypeOf: () => model.prototype,
|
|
527
|
+
get(l, key) {
|
|
528
|
+
if (key === _original) return l
|
|
529
|
+
|
|
530
|
+
const val = l[key];
|
|
531
|
+
return isFunction(val) ? proxify(val, {
|
|
532
|
+
apply(fn, ctx, args) {
|
|
533
|
+
if (has(mutators, key)) {
|
|
534
|
+
// indexes of arguments to check def + cast
|
|
535
|
+
const [begin, end = args.length - 1, getArgDef] = mutators[key];
|
|
536
|
+
for (let i = begin; i <= end; i++) {
|
|
537
|
+
const argDef = getArgDef ? getArgDef(i) : model.definition;
|
|
538
|
+
args[i] = checkDefinition(
|
|
539
|
+
args[i],
|
|
540
|
+
argDef,
|
|
541
|
+
`${base.name}.${key} arguments[${i}]`,
|
|
542
|
+
model.errors,
|
|
543
|
+
[],
|
|
544
|
+
true
|
|
545
|
+
);
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
if (model.assertions.length > 0) {
|
|
549
|
+
const testingClone = clone(l);
|
|
550
|
+
fn.apply(testingClone, args);
|
|
551
|
+
checkAssertions(testingClone, model, `after ${key} mutation`);
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
unstackErrors(model);
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
return fn.apply(l, args)
|
|
558
|
+
}
|
|
559
|
+
}) : val
|
|
560
|
+
}
|
|
561
|
+
}, otherTraps))
|
|
562
562
|
};
|
|
563
563
|
|
|
564
564
|
function ArrayModel(initialDefinition) {
|