objectmodel 4.4.7 → 4.4.8
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/bundle-entry.dev.js +2 -2
- package/build/bundle-entry.js +11 -11
- package/dist/object-model.cjs +85 -90
- package/dist/object-model.js +85 -90
- 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 +4 -4
- package/package.json +3 -3
- package/rollup.config.js +13 -13
- package/src/helpers.js +43 -43
- package/src/list-model.js +43 -43
- package/src/object-model.js +2 -7
- package/test/basic-model.spec.cjs +272 -272
- 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 +236 -236
- package/test/model.spec.cjs +30 -30
- package/test/set-model.spec.cjs +222 -222
- package/test/umd.html +25 -25
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
|
|
@@ -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.8 - 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
|
|
@@ -115,13 +115,8 @@ const
|
|
|
115
115
|
isModelInstance = i => i && getProto(i) && is(Model, getProto(i).constructor),
|
|
116
116
|
|
|
117
117
|
parseDefinition = (def) => {
|
|
118
|
-
if (isPlainObject(def)) {
|
|
119
|
-
def = {};
|
|
120
|
-
for (let key in def) { def[key] = parseDefinition(def[key]); }
|
|
121
|
-
}
|
|
122
118
|
if (!Array.isArray(def)) return [def]
|
|
123
119
|
else if (def.length === 1) return [def[0], undefined, null]
|
|
124
|
-
|
|
125
120
|
return def
|
|
126
121
|
},
|
|
127
122
|
|
|
@@ -160,10 +155,10 @@ const
|
|
|
160
155
|
def[_check](obj, path, errors, stack.concat(def), shouldCast);
|
|
161
156
|
}
|
|
162
157
|
else if (isPlainObject(def)) {
|
|
163
|
-
|
|
158
|
+
Object.keys(def).forEach(key => {
|
|
164
159
|
const val = obj ? obj[key] : undefined;
|
|
165
160
|
checkDefinition(val, def[key], formatPath(path, key), errors, stack, shouldCast);
|
|
166
|
-
}
|
|
161
|
+
});
|
|
167
162
|
}
|
|
168
163
|
else {
|
|
169
164
|
const pdef = parseDefinition(def);
|
|
@@ -521,45 +516,45 @@ extend(Any.remaining, Any, {
|
|
|
521
516
|
});
|
|
522
517
|
Any[Symbol.iterator] = function* () { yield new Any.remaining(this.definition); };
|
|
523
518
|
|
|
524
|
-
const initListModel = (base, constructor, def, init, clone, mutators, otherTraps) => {
|
|
525
|
-
|
|
526
|
-
return initModel(def, constructor, base, init, model => Object.assign({
|
|
527
|
-
getPrototypeOf: () => model.prototype,
|
|
528
|
-
get(l, key) {
|
|
529
|
-
if (key === _original) return l
|
|
530
|
-
|
|
531
|
-
const val = l[key];
|
|
532
|
-
return isFunction(val) ? proxify(val, {
|
|
533
|
-
apply(fn, ctx, args) {
|
|
534
|
-
if (has(mutators, key)) {
|
|
535
|
-
// indexes of arguments to check def + cast
|
|
536
|
-
const [begin, end = args.length - 1, getArgDef] = mutators[key];
|
|
537
|
-
for (let i = begin; i <= end; i++) {
|
|
538
|
-
const argDef = getArgDef ? getArgDef(i) : model.definition;
|
|
539
|
-
args[i] = checkDefinition(
|
|
540
|
-
args[i],
|
|
541
|
-
argDef,
|
|
542
|
-
`${base.name}.${key} arguments[${i}]`,
|
|
543
|
-
model.errors,
|
|
544
|
-
[],
|
|
545
|
-
true
|
|
546
|
-
);
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
if (model.assertions.length > 0) {
|
|
550
|
-
const testingClone = clone(l);
|
|
551
|
-
fn.apply(testingClone, args);
|
|
552
|
-
checkAssertions(testingClone, model, `after ${key} mutation`);
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
unstackErrors(model);
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
return fn.apply(l, args)
|
|
559
|
-
}
|
|
560
|
-
}) : val
|
|
561
|
-
}
|
|
562
|
-
}, otherTraps))
|
|
519
|
+
const initListModel = (base, constructor, def, init, clone, mutators, otherTraps) => {
|
|
520
|
+
|
|
521
|
+
return initModel(def, constructor, base, init, model => Object.assign({
|
|
522
|
+
getPrototypeOf: () => model.prototype,
|
|
523
|
+
get(l, key) {
|
|
524
|
+
if (key === _original) return l
|
|
525
|
+
|
|
526
|
+
const val = l[key];
|
|
527
|
+
return isFunction(val) ? proxify(val, {
|
|
528
|
+
apply(fn, ctx, args) {
|
|
529
|
+
if (has(mutators, key)) {
|
|
530
|
+
// indexes of arguments to check def + cast
|
|
531
|
+
const [begin, end = args.length - 1, getArgDef] = mutators[key];
|
|
532
|
+
for (let i = begin; i <= end; i++) {
|
|
533
|
+
const argDef = getArgDef ? getArgDef(i) : model.definition;
|
|
534
|
+
args[i] = checkDefinition(
|
|
535
|
+
args[i],
|
|
536
|
+
argDef,
|
|
537
|
+
`${base.name}.${key} arguments[${i}]`,
|
|
538
|
+
model.errors,
|
|
539
|
+
[],
|
|
540
|
+
true
|
|
541
|
+
);
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
if (model.assertions.length > 0) {
|
|
545
|
+
const testingClone = clone(l);
|
|
546
|
+
fn.apply(testingClone, args);
|
|
547
|
+
checkAssertions(testingClone, model, `after ${key} mutation`);
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
unstackErrors(model);
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
return fn.apply(l, args)
|
|
554
|
+
}
|
|
555
|
+
}) : val
|
|
556
|
+
}
|
|
557
|
+
}, otherTraps))
|
|
563
558
|
};
|
|
564
559
|
|
|
565
560
|
function ArrayModel(initialDefinition) {
|