objectmodel 4.4.4 → 4.4.6
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/build/update-docs.js +1 -1
- package/dist/object-model.cjs +111 -110
- package/dist/object-model.js +86 -83
- package/dist/object-model.js.map +1 -1
- package/dist/object-model.min.js +4 -2
- package/dist/object-model.min.js.map +1 -1
- package/index.html +4 -4
- package/package.json +74 -70
- package/rollup.config.js +13 -13
- package/src/helpers.js +43 -43
- package/src/list-model.js +43 -43
- package/src/object-model.d.ts +11 -10
- package/src/object-model.js +1 -0
- package/test/basic-model.spec.cjs +272 -272
- package/test/basic-model.test-d.ts +1 -0
- 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/object-model.spec.cjs +2 -1
- package/test/object-model.test-d.ts +9 -2
- package/test/set-model.spec.cjs +222 -222
- package/test/umd.html +25 -25
- package/types/index.d.ts +3 -1
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'
|
|
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' with { 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/build/update-docs.js
CHANGED
|
@@ -2,7 +2,7 @@ import fs from 'fs';
|
|
|
2
2
|
import filesize from 'pretty-bytes';
|
|
3
3
|
import { gzipSizeSync } from 'gzip-size';
|
|
4
4
|
|
|
5
|
-
import pkg from '../package.json'
|
|
5
|
+
import pkg from '../package.json' with { type: 'json' };
|
|
6
6
|
|
|
7
7
|
function updateIndex(html){
|
|
8
8
|
const libPath = "./dist/object-model.min.js"
|
package/dist/object-model.cjs
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
// ObjectModel v4.4.
|
|
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);
|
|
46
|
-
};
|
|
47
|
-
|
|
1
|
+
// ObjectModel v4.4.5 - http://objectmodel.js.org
|
|
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);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
48
|
const
|
|
49
49
|
_check = Symbol(),
|
|
50
50
|
_checked = Symbol(), // used to skip validation at instanciation for perf
|
|
@@ -102,6 +102,7 @@ const
|
|
|
102
102
|
err.message = "expecting " + (err.path ? err.path + " to be " : "") + formatDefinition(err.expected)
|
|
103
103
|
+ ", got " + (err.received != null ? bettertypeof(err.received) + " " : "") + format$1(err.received);
|
|
104
104
|
}
|
|
105
|
+
err.model = model;
|
|
105
106
|
return err
|
|
106
107
|
});
|
|
107
108
|
|
|
@@ -518,49 +519,49 @@ Any.remaining = function (def) { this.definition = def; };
|
|
|
518
519
|
extend(Any.remaining, Any, {
|
|
519
520
|
toString() { return "..." + formatDefinition(this.definition) }
|
|
520
521
|
});
|
|
521
|
-
Any[Symbol.iterator] = function* () { yield new Any.remaining(this.definition); };
|
|
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))
|
|
562
|
-
};
|
|
563
|
-
|
|
522
|
+
Any[Symbol.iterator] = function* () { yield new Any.remaining(this.definition); };
|
|
523
|
+
|
|
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))
|
|
563
|
+
};
|
|
564
|
+
|
|
564
565
|
function ArrayModel(initialDefinition) {
|
|
565
566
|
const model = initListModel(
|
|
566
567
|
Array,
|
|
@@ -622,8 +623,8 @@ const controlMutation = (model, array, key, value, applyMutation, canBeExtended)
|
|
|
622
623
|
const isSuccess = !unstackErrors(model);
|
|
623
624
|
if (isSuccess) applyMutation(array, value);
|
|
624
625
|
return isSuccess
|
|
625
|
-
};
|
|
626
|
-
|
|
626
|
+
};
|
|
627
|
+
|
|
627
628
|
function SetModel(initialDefinition) {
|
|
628
629
|
const model = initListModel(
|
|
629
630
|
Set,
|
|
@@ -658,8 +659,8 @@ extend(SetModel, Model, {
|
|
|
658
659
|
extend(...newParts) {
|
|
659
660
|
return extendModel(new SetModel(extendDefinition(this.definition, newParts)), this)
|
|
660
661
|
}
|
|
661
|
-
});
|
|
662
|
-
|
|
662
|
+
});
|
|
663
|
+
|
|
663
664
|
function MapModel(initialKeyDefinition, initialValueDefinition) {
|
|
664
665
|
const getDef = i => i === 0 ? model.definition.key : model.definition.value;
|
|
665
666
|
const model = initListModel(
|
|
@@ -701,8 +702,8 @@ extend(MapModel, Model, {
|
|
|
701
702
|
extendDefinition(this.definition.value, valueParts)
|
|
702
703
|
), this)
|
|
703
704
|
}
|
|
704
|
-
});
|
|
705
|
-
|
|
705
|
+
});
|
|
706
|
+
|
|
706
707
|
function FunctionModel(...argsDef) {
|
|
707
708
|
return initModel({ arguments: argsDef }, FunctionModel, Function, null, model => ({
|
|
708
709
|
getPrototypeOf: () => model.prototype,
|
|
@@ -755,8 +756,8 @@ extend(FunctionModel, Model, {
|
|
|
755
756
|
[_check](f, path, errors) {
|
|
756
757
|
if (!isFunction(f)) stackError(errors, "Function", f, path);
|
|
757
758
|
}
|
|
758
|
-
});
|
|
759
|
-
|
|
759
|
+
});
|
|
760
|
+
|
|
760
761
|
const styles = {
|
|
761
762
|
list: "list-style-type: none; padding: 0; margin: 0;",
|
|
762
763
|
listItem: "padding: 0 0 0 1em;",
|
|
@@ -948,16 +949,16 @@ const ModelInstanceFormatter = {
|
|
|
948
949
|
if (typeof window !== "undefined") {
|
|
949
950
|
window.devtoolsFormatters = (window.devtoolsFormatters || [])
|
|
950
951
|
.concat(ModelFormatter, ModelInstanceFormatter);
|
|
951
|
-
}
|
|
952
|
-
|
|
953
|
-
;
|
|
954
|
-
//# sourceMappingURL=object-model.js.map
|
|
955
|
-
|
|
956
|
-
exports.Any=Any;
|
|
957
|
-
exports.ArrayModel=ArrayModel;
|
|
958
|
-
exports.BasicModel=BasicModel;
|
|
959
|
-
exports.FunctionModel=FunctionModel;
|
|
960
|
-
exports.MapModel=MapModel;
|
|
961
|
-
exports.Model=Model;
|
|
962
|
-
exports.ObjectModel=ObjectModel;
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
;
|
|
955
|
+
//# sourceMappingURL=object-model.js.map
|
|
956
|
+
|
|
957
|
+
exports.Any=Any;
|
|
958
|
+
exports.ArrayModel=ArrayModel;
|
|
959
|
+
exports.BasicModel=BasicModel;
|
|
960
|
+
exports.FunctionModel=FunctionModel;
|
|
961
|
+
exports.MapModel=MapModel;
|
|
962
|
+
exports.Model=Model;
|
|
963
|
+
exports.ObjectModel=ObjectModel;
|
|
963
964
|
exports.SetModel=SetModel;
|