objectmodel 4.2.3 → 4.3.1
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/build/{add-banner.cjs → add-banner.js} +2 -2
- package/build/{update-docs.cjs → update-docs.js} +7 -5
- package/dist/object-model.cjs +493 -490
- package/dist/object-model.js +493 -490
- 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 +1603 -1605
- package/package.json +64 -60
- package/src/object-model.js +479 -476
- package/test/any-model.spec.cjs +68 -68
- package/test/array-model.spec.cjs +0 -1
- package/test/index.html +27 -27
- package/test/object-model.spec.cjs +39 -0
- package/test/umd.html +8 -8
- package/types/index.d.ts +138 -136
- package/test/lib/qunit.css +0 -436
- package/test/lib/qunit.js +0 -6582
- package/tsconfig.json +0 -10
package/test/any-model.spec.cjs
CHANGED
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
/* global QUnit, Any, Model, BasicModel, FunctionModel */
|
|
2
|
-
|
|
3
|
-
QUnit.module("Any Model");
|
|
4
|
-
|
|
5
|
-
QUnit.test("any model validation", function (assert) {
|
|
6
|
-
assert.ok(Any instanceof Model, "Any is instance of Model")
|
|
7
|
-
assert.ok(Any instanceof BasicModel, "Any is instance of BasicModel")
|
|
8
|
-
assert.ok(Any.test(undefined), "testing undefined")
|
|
9
|
-
assert.ok(Any.test(null), "testing null")
|
|
10
|
-
assert.ok(Any.test(0), "testing 0")
|
|
11
|
-
assert.ok(Any.test(1), "testing 1")
|
|
12
|
-
assert.ok(Any.test(""), "testing empty string")
|
|
13
|
-
assert.ok(Any.test("test"), "testing string")
|
|
14
|
-
assert.ok(Any.test(false), "testing false")
|
|
15
|
-
assert.ok(Any.test(true), "testing true")
|
|
16
|
-
assert.ok(Any.test({}), "testing object")
|
|
17
|
-
assert.ok(Any.test([]), "testing array")
|
|
18
|
-
assert.ok(Any.test(function () { }), "testing function")
|
|
19
|
-
assert.ok(Any.test(Symbol()), "testing symbol")
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
QUnit.test("any as objectmodel property", function (assert) {
|
|
23
|
-
let M = Model({ x: Any })
|
|
24
|
-
assert.ok(M({}) instanceof M, "testing no prop")
|
|
25
|
-
assert.ok(M({ x: undefined }).x === undefined, "testing undefined prop")
|
|
26
|
-
assert.ok(M({ x: null }).x === null, "testing null prop")
|
|
27
|
-
assert.ok(M({ x: 0 }).x === 0, "testing 0 prop")
|
|
28
|
-
assert.ok(M({ x: 1 }).x === 1, "testing 1 prop")
|
|
29
|
-
assert.ok(M({ x: false }).x === false, "testing false prop")
|
|
30
|
-
assert.ok(M({ x: "" }).x === "", "testing empty string prop")
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
QUnit.test("any for remaining function models arguments", function (assert) {
|
|
34
|
-
let Operation = FunctionModel(...Any).return(Number)
|
|
35
|
-
let add = Operation((...args) => args.reduce((total, n) => total + n, 0))
|
|
36
|
-
assert.strictEqual(add(), 0, "testing 0 args")
|
|
37
|
-
assert.strictEqual(add(1), 1, "testing 1 arg")
|
|
38
|
-
assert.strictEqual(add(1, 2), 3, "testing 2 args")
|
|
39
|
-
assert.strictEqual(add(1, 2, 3, 4, 5), 15, "testing N args")
|
|
40
|
-
|
|
41
|
-
let TwoArgsOrMore = FunctionModel(Number, Number, ...Any)
|
|
42
|
-
add = TwoArgsOrMore((...args) => args.reduce((total, n) => total + n, 0))
|
|
43
|
-
assert.throws(() => { add() }, /TypeError.*arguments\[0]/, 1, "testing 0 args with 2 required")
|
|
44
|
-
assert.throws(() => { add(1) }, /TypeError.*arguments\[1]/, 1, "testing 1 arg with 2 required")
|
|
45
|
-
assert.strictEqual(add(1, 2), 3, "testing 2 args with 2 required")
|
|
46
|
-
assert.strictEqual(add(1, 2, 3, 4, 5), 15, "testing N args with 2 required")
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
QUnit.test("any for typed remaining function models arguments", function (assert) {
|
|
50
|
-
let Operation = FunctionModel(...Any(Number)).return(Number)
|
|
51
|
-
let add = Operation((...args) => args.reduce((total, n) => total + n, 0))
|
|
52
|
-
assert.strictEqual(add(), 0, "testing 0 args")
|
|
53
|
-
assert.strictEqual(add(1), 1, "testing 1 arg")
|
|
54
|
-
assert.strictEqual(add(1, 2), 3, "testing 2 args")
|
|
55
|
-
assert.strictEqual(add(1, 2, 3, 4, 5), 15, "testing N args")
|
|
56
|
-
assert.throws(() => { add(1, 2, 3, "4") }, /TypeError.*arguments\[3]/, "testing invalid typed remaining arg")
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
QUnit.test("any model formatter", function (assert) {
|
|
60
|
-
assert.strictEqual(Any.toString(), "Any", "Any toString")
|
|
61
|
-
let Operation = FunctionModel(...Any).return(Number)
|
|
62
|
-
assert.strictEqual(Operation.toString(), "Function(...Any) => Number", "Any remaining toString")
|
|
63
|
-
|
|
64
|
-
let TwoArgsOrMore = FunctionModel(Number, Number, ...Any)
|
|
65
|
-
assert.strictEqual(TwoArgsOrMore.toString(), "Function(Number, Number, ...Any)", "Any remaining with other args toString")
|
|
66
|
-
|
|
67
|
-
Operation = FunctionModel(...Any(Number)).return(Number)
|
|
68
|
-
assert.strictEqual(Operation.toString(), "Function(...Number) => Number", "Any remaining with definition toString")
|
|
1
|
+
/* global QUnit, Any, Model, BasicModel, FunctionModel */
|
|
2
|
+
|
|
3
|
+
QUnit.module("Any Model");
|
|
4
|
+
|
|
5
|
+
QUnit.test("any model validation", function (assert) {
|
|
6
|
+
assert.ok(Any instanceof Model, "Any is instance of Model")
|
|
7
|
+
assert.ok(Any instanceof BasicModel, "Any is instance of BasicModel")
|
|
8
|
+
assert.ok(Any.test(undefined), "testing undefined")
|
|
9
|
+
assert.ok(Any.test(null), "testing null")
|
|
10
|
+
assert.ok(Any.test(0), "testing 0")
|
|
11
|
+
assert.ok(Any.test(1), "testing 1")
|
|
12
|
+
assert.ok(Any.test(""), "testing empty string")
|
|
13
|
+
assert.ok(Any.test("test"), "testing string")
|
|
14
|
+
assert.ok(Any.test(false), "testing false")
|
|
15
|
+
assert.ok(Any.test(true), "testing true")
|
|
16
|
+
assert.ok(Any.test({}), "testing object")
|
|
17
|
+
assert.ok(Any.test([]), "testing array")
|
|
18
|
+
assert.ok(Any.test(function () { }), "testing function")
|
|
19
|
+
assert.ok(Any.test(Symbol()), "testing symbol")
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
QUnit.test("any as objectmodel property", function (assert) {
|
|
23
|
+
let M = Model({ x: Any })
|
|
24
|
+
assert.ok(M({}) instanceof M, "testing no prop")
|
|
25
|
+
assert.ok(M({ x: undefined }).x === undefined, "testing undefined prop")
|
|
26
|
+
assert.ok(M({ x: null }).x === null, "testing null prop")
|
|
27
|
+
assert.ok(M({ x: 0 }).x === 0, "testing 0 prop")
|
|
28
|
+
assert.ok(M({ x: 1 }).x === 1, "testing 1 prop")
|
|
29
|
+
assert.ok(M({ x: false }).x === false, "testing false prop")
|
|
30
|
+
assert.ok(M({ x: "" }).x === "", "testing empty string prop")
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
QUnit.test("any for remaining function models arguments", function (assert) {
|
|
34
|
+
let Operation = FunctionModel(...Any).return(Number)
|
|
35
|
+
let add = Operation((...args) => args.reduce((total, n) => total + n, 0))
|
|
36
|
+
assert.strictEqual(add(), 0, "testing 0 args")
|
|
37
|
+
assert.strictEqual(add(1), 1, "testing 1 arg")
|
|
38
|
+
assert.strictEqual(add(1, 2), 3, "testing 2 args")
|
|
39
|
+
assert.strictEqual(add(1, 2, 3, 4, 5), 15, "testing N args")
|
|
40
|
+
|
|
41
|
+
let TwoArgsOrMore = FunctionModel(Number, Number, ...Any)
|
|
42
|
+
add = TwoArgsOrMore((...args) => args.reduce((total, n) => total + n, 0))
|
|
43
|
+
assert.throws(() => { add() }, /TypeError.*arguments\[0]/, 1, "testing 0 args with 2 required")
|
|
44
|
+
assert.throws(() => { add(1) }, /TypeError.*arguments\[1]/, 1, "testing 1 arg with 2 required")
|
|
45
|
+
assert.strictEqual(add(1, 2), 3, "testing 2 args with 2 required")
|
|
46
|
+
assert.strictEqual(add(1, 2, 3, 4, 5), 15, "testing N args with 2 required")
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
QUnit.test("any for typed remaining function models arguments", function (assert) {
|
|
50
|
+
let Operation = FunctionModel(...Any(Number)).return(Number)
|
|
51
|
+
let add = Operation((...args) => args.reduce((total, n) => total + n, 0))
|
|
52
|
+
assert.strictEqual(add(), 0, "testing 0 args")
|
|
53
|
+
assert.strictEqual(add(1), 1, "testing 1 arg")
|
|
54
|
+
assert.strictEqual(add(1, 2), 3, "testing 2 args")
|
|
55
|
+
assert.strictEqual(add(1, 2, 3, 4, 5), 15, "testing N args")
|
|
56
|
+
assert.throws(() => { add(1, 2, 3, "4") }, /TypeError.*arguments\[3]/, "testing invalid typed remaining arg")
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
QUnit.test("any model formatter", function (assert) {
|
|
60
|
+
assert.strictEqual(Any.toString(), "Any", "Any toString")
|
|
61
|
+
let Operation = FunctionModel(...Any).return(Number)
|
|
62
|
+
assert.strictEqual(Operation.toString(), "Function(...Any) => Number", "Any remaining toString")
|
|
63
|
+
|
|
64
|
+
let TwoArgsOrMore = FunctionModel(Number, Number, ...Any)
|
|
65
|
+
assert.strictEqual(TwoArgsOrMore.toString(), "Function(Number, Number, ...Any)", "Any remaining with other args toString")
|
|
66
|
+
|
|
67
|
+
Operation = FunctionModel(...Any(Number)).return(Number)
|
|
68
|
+
assert.strictEqual(Operation.toString(), "Function(...Number) => Number", "Any remaining with definition toString")
|
|
69
69
|
})
|
|
@@ -16,7 +16,6 @@ QUnit.test("constructor && proto", function (assert) {
|
|
|
16
16
|
assert.ok(Arr.definition === Number, "test Array model prop definition");
|
|
17
17
|
assert.ok(typeof Arr.assertions === "object", "test Array model prop assertions");
|
|
18
18
|
|
|
19
|
-
|
|
20
19
|
assert.ok(ArrayModel(undefined) instanceof ArrayModel, "ArrayModel can receive undefined as argument");
|
|
21
20
|
});
|
|
22
21
|
|
package/test/index.html
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html>
|
|
3
|
-
|
|
4
|
-
<head>
|
|
5
|
-
<meta charset="utf-8">
|
|
6
|
-
<title>QUnit - ObjectModel unit tests</title>
|
|
7
|
-
<link rel="stylesheet" href="
|
|
8
|
-
<script src="
|
|
9
|
-
<script type="module">
|
|
10
|
-
import * as globals from "../dist/object-model.min.js"
|
|
11
|
-
Object.assign(window, globals)
|
|
12
|
-
</script>
|
|
13
|
-
<script src="model.spec.cjs"></script>
|
|
14
|
-
<script src="basic-model.spec.cjs"></script>
|
|
15
|
-
<script src="any-model.spec.cjs"></script>
|
|
16
|
-
<script src="object-model.spec.cjs"></script>
|
|
17
|
-
<script src="array-model.spec.cjs"></script>
|
|
18
|
-
<script src="function-model.spec.cjs"></script>
|
|
19
|
-
<script src="map-model.spec.cjs"></script>
|
|
20
|
-
<script src="set-model.spec.cjs"></script>
|
|
21
|
-
</head>
|
|
22
|
-
|
|
23
|
-
<body>
|
|
24
|
-
<div id="qunit"></div>
|
|
25
|
-
<div id="qunit-fixture"></div>
|
|
26
|
-
</body>
|
|
27
|
-
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
<title>QUnit - ObjectModel unit tests</title>
|
|
7
|
+
<link rel="stylesheet" href="https://code.jquery.com/qunit/qunit-2.17.2.css">
|
|
8
|
+
<script src="https://code.jquery.com/qunit/qunit-2.17.2.js"></script>
|
|
9
|
+
<script type="module">
|
|
10
|
+
import * as globals from "../dist/object-model.min.js"
|
|
11
|
+
Object.assign(window, globals)
|
|
12
|
+
</script>
|
|
13
|
+
<script src="model.spec.cjs"></script>
|
|
14
|
+
<script src="basic-model.spec.cjs"></script>
|
|
15
|
+
<script src="any-model.spec.cjs"></script>
|
|
16
|
+
<script src="object-model.spec.cjs"></script>
|
|
17
|
+
<script src="array-model.spec.cjs"></script>
|
|
18
|
+
<script src="function-model.spec.cjs"></script>
|
|
19
|
+
<script src="map-model.spec.cjs"></script>
|
|
20
|
+
<script src="set-model.spec.cjs"></script>
|
|
21
|
+
</head>
|
|
22
|
+
|
|
23
|
+
<body>
|
|
24
|
+
<div id="qunit"></div>
|
|
25
|
+
<div id="qunit-fixture"></div>
|
|
26
|
+
</body>
|
|
27
|
+
|
|
28
28
|
</html>
|
|
@@ -1305,4 +1305,43 @@ QUnit.test("Null-safe object traversal", function (assert) {
|
|
|
1305
1305
|
assert.strictEqual(config.local.time.format, undefined, "null-safe object traversal getter")
|
|
1306
1306
|
config.local.time.format = "12h";
|
|
1307
1307
|
assert.strictEqual(config.local.time.format, "12h", "null-safe object traversal setter")
|
|
1308
|
+
})
|
|
1309
|
+
|
|
1310
|
+
QUnit.test("Check once mode", function(assert){
|
|
1311
|
+
const Address = Model({ city: String, street: { name: String, number: Number }})
|
|
1312
|
+
assert.throws(function () {
|
|
1313
|
+
Address({ city: "Paris", street: { name: null, number: 12 }}, Model.CHECK_ONCE)
|
|
1314
|
+
}, /TypeError.*expecting street.name to be String/, "check once mode still checks at instanciation")
|
|
1315
|
+
const a = new Address({ city: "Paris", street: { name: "Champs-Elysees", number: 12 }}, Model.CHECK_ONCE)
|
|
1316
|
+
a.street.name = null;
|
|
1317
|
+
assert.strictEqual(a.street.name, null, "check once mode does not check future mutations")
|
|
1318
|
+
|
|
1319
|
+
class Person extends Model({ name: String, age: Number }) {
|
|
1320
|
+
constructor({ name, age }) {
|
|
1321
|
+
super({ name, age }, Model.CHECK_ONCE)
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1324
|
+
|
|
1325
|
+
const john = new Person({ name: "John", age: 32 })
|
|
1326
|
+
john.age = "twelve";
|
|
1327
|
+
assert.strictEqual(john.age, "twelve", "check once mode does not check future mutations for extended class-based models")
|
|
1328
|
+
})
|
|
1329
|
+
|
|
1330
|
+
QUnit.test("Short-circuit validation when not receiving an object as expected", function(assert){
|
|
1331
|
+
const PersonModel = new ObjectModel({
|
|
1332
|
+
FirstName: String,
|
|
1333
|
+
LastName: String,
|
|
1334
|
+
})
|
|
1335
|
+
const errorsCollected = []
|
|
1336
|
+
PersonModel.errorCollector = function(errors){
|
|
1337
|
+
errorsCollected.push(...errors)
|
|
1338
|
+
}
|
|
1339
|
+
|
|
1340
|
+
PersonModel(42)
|
|
1341
|
+
console.log({ errorsCollected})
|
|
1342
|
+
assert.equal(errorsCollected.length, 1, "should only have 1 error")
|
|
1343
|
+
assert.equal(errorsCollected[0].message, `expecting {
|
|
1344
|
+
FirstName: String,
|
|
1345
|
+
LastName: String
|
|
1346
|
+
}, got Number 42`)
|
|
1308
1347
|
})
|
package/test/umd.html
CHANGED
|
@@ -8,14 +8,14 @@
|
|
|
8
8
|
<script src="lib/qunit.js"></script>
|
|
9
9
|
<script src="https://umd.cdn.pika.dev/objectmodel/v4"></script>
|
|
10
10
|
<script>const { Model, BasicModel, ObjectModel, ArrayModel, FunctionModel, MapModel, SetModel, Any } = objectmodel</script>
|
|
11
|
-
<script src="model.spec.
|
|
12
|
-
<script src="basic-model.spec.
|
|
13
|
-
<script src="any-model.spec.
|
|
14
|
-
<script src="object-model.spec.
|
|
15
|
-
<script src="array-model.spec.
|
|
16
|
-
<script src="function-model.spec.
|
|
17
|
-
<script src="map-model.spec.
|
|
18
|
-
<script src="set-model.spec.
|
|
11
|
+
<script src="model.spec.cjs"></script>
|
|
12
|
+
<script src="basic-model.spec.cjs"></script>
|
|
13
|
+
<script src="any-model.spec.cjs"></script>
|
|
14
|
+
<script src="object-model.spec.cjs"></script>
|
|
15
|
+
<script src="array-model.spec.cjs"></script>
|
|
16
|
+
<script src="function-model.spec.cjs"></script>
|
|
17
|
+
<script src="map-model.spec.cjs"></script>
|
|
18
|
+
<script src="set-model.spec.cjs"></script>
|
|
19
19
|
</head>
|
|
20
20
|
|
|
21
21
|
<body>
|
package/types/index.d.ts
CHANGED
|
@@ -1,136 +1,138 @@
|
|
|
1
|
-
// TypeScript definition file for ObjectModel
|
|
2
|
-
|
|
3
|
-
export interface Model {
|
|
4
|
-
(value?: any): any;
|
|
5
|
-
|
|
6
|
-
definition: any;
|
|
7
|
-
assertions: Assertion[];
|
|
8
|
-
default: any;
|
|
9
|
-
name: string;
|
|
10
|
-
|
|
11
|
-
conventionForConstant(variableName: string): boolean;
|
|
12
|
-
conventionForPrivate(variableName: string): boolean;
|
|
13
|
-
|
|
14
|
-
toString(stack?: any[]): string;
|
|
15
|
-
|
|
16
|
-
as(name: string): this;
|
|
17
|
-
|
|
18
|
-
defaultTo(defaultValue: any): this;
|
|
19
|
-
|
|
20
|
-
test(value: any, errorCollector?: (errors: ModelError[]) => void): boolean;
|
|
21
|
-
|
|
22
|
-
errorCollector(errors: ModelError[]): void;
|
|
23
|
-
|
|
24
|
-
assert(assertion: Assertion, description?: string | Function): this;
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface ModelConstructor {
|
|
29
|
-
(definition: any): ObjectModel;
|
|
30
|
-
new(definition: any): ObjectModel;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
<T>(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
(
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
(
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
export const
|
|
132
|
-
export const
|
|
133
|
-
export const
|
|
134
|
-
export const
|
|
135
|
-
export const
|
|
136
|
-
export const
|
|
1
|
+
// TypeScript definition file for ObjectModel
|
|
2
|
+
|
|
3
|
+
export interface Model {
|
|
4
|
+
(value?: any): any;
|
|
5
|
+
|
|
6
|
+
definition: any;
|
|
7
|
+
assertions: Assertion[];
|
|
8
|
+
default: any;
|
|
9
|
+
name: string;
|
|
10
|
+
|
|
11
|
+
conventionForConstant(variableName: string): boolean;
|
|
12
|
+
conventionForPrivate(variableName: string): boolean;
|
|
13
|
+
|
|
14
|
+
toString(stack?: any[]): string;
|
|
15
|
+
|
|
16
|
+
as(name: string): this;
|
|
17
|
+
|
|
18
|
+
defaultTo(defaultValue: any): this;
|
|
19
|
+
|
|
20
|
+
test(value: any, errorCollector?: (errors: ModelError[]) => void): boolean;
|
|
21
|
+
|
|
22
|
+
errorCollector(errors: ModelError[]): void;
|
|
23
|
+
|
|
24
|
+
assert(assertion: Assertion, description?: string | Function): this;
|
|
25
|
+
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface ModelConstructor {
|
|
29
|
+
(definition: any): ObjectModel;
|
|
30
|
+
new(definition: any): ObjectModel;
|
|
31
|
+
CHECK_ONCE: symbol;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface BasicModel extends Model {
|
|
35
|
+
(): any;
|
|
36
|
+
new(): any;
|
|
37
|
+
(value: any): any
|
|
38
|
+
new(value: any): any
|
|
39
|
+
|
|
40
|
+
extend(...otherDefinitions: Array<any>): this;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface BasicModelConstructor {
|
|
44
|
+
(definition: any): BasicModel
|
|
45
|
+
new(definition: any): BasicModel;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface ObjectModel extends Model {
|
|
49
|
+
(): Object;
|
|
50
|
+
new(): Object;
|
|
51
|
+
(object: object): Object;
|
|
52
|
+
new(object: object): Object;
|
|
53
|
+
|
|
54
|
+
extend(...otherDefinitions: Array<Object | ObjectModel>): this;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface ObjectModelConstructor {
|
|
58
|
+
(definition: Object): ObjectModel;
|
|
59
|
+
new(definition: Object): ObjectModel;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface ArrayModel extends Model {
|
|
63
|
+
<T>(): Array<T>;
|
|
64
|
+
new <T>(): Array<T>;
|
|
65
|
+
<T>(array: Array<T>): Array<T>;
|
|
66
|
+
new <T>(array: Array<T>): Array<T>;
|
|
67
|
+
|
|
68
|
+
extend(...otherElementDefinitions: Array<any>): this;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface ArrayModelConstructor {
|
|
72
|
+
(itemDefinition: any): ArrayModel;
|
|
73
|
+
new(itemDefinition: any): ArrayModel;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface FunctionModel extends Model {
|
|
77
|
+
(): Function;
|
|
78
|
+
new(): Function;
|
|
79
|
+
(fn: Function): Function;
|
|
80
|
+
new(fn: Function): Function;
|
|
81
|
+
|
|
82
|
+
definition: { arguments: any[], return: any };
|
|
83
|
+
|
|
84
|
+
return(returnValueDefinition: any): FunctionModel;
|
|
85
|
+
|
|
86
|
+
extend(otherArgsDefinitions: Array<any>, otherReturnValuesDefinitions: Array<any>): this;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface FunctionModelConstructor {
|
|
90
|
+
(...argumentsDefinitions: any[]): FunctionModel;
|
|
91
|
+
new(...argumentsDefinitions: any[]): FunctionModel;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface MapModel extends Model {
|
|
95
|
+
(): Map<any, any>;
|
|
96
|
+
new(): Map<any, any>;
|
|
97
|
+
(iterable: Map<any, any> | Array<[any, any]>): Map<any, any>;
|
|
98
|
+
new(iterable: Map<any, any> | Array<[any, any]>): Map<any, any>;
|
|
99
|
+
|
|
100
|
+
extend(otherKeyDefinitions: Array<any>, otherValueDefinitions: Array<any>): this;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export interface MapModelConstructor {
|
|
104
|
+
(keyDefinition: any, valueDefinition: any): MapModel;
|
|
105
|
+
new(keyDefinition: any, valueDefinition: any): MapModel;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export interface SetModel extends Model {
|
|
109
|
+
(): Set<any>;
|
|
110
|
+
new(): Set<any>;
|
|
111
|
+
(set: Set<any> | Array<any>): Set<any>;
|
|
112
|
+
new(set: Set<any> | Array<any>): Set<any>;
|
|
113
|
+
|
|
114
|
+
extend(...otherElementDefinitions: Array<any>): this;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export interface SetModelConstructor {
|
|
118
|
+
(itemDefinition: any): SetModel;
|
|
119
|
+
new(itemDefinition: any): SetModel;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export type Assertion = (variable: any) => boolean
|
|
123
|
+
|
|
124
|
+
export interface ModelError {
|
|
125
|
+
message: string;
|
|
126
|
+
expected: any;
|
|
127
|
+
received: any;
|
|
128
|
+
path: string;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export const Any: any;
|
|
132
|
+
export const Model: ModelConstructor;
|
|
133
|
+
export const BasicModel: BasicModelConstructor;
|
|
134
|
+
export const ObjectModel: ObjectModelConstructor;
|
|
135
|
+
export const ArrayModel: ArrayModelConstructor;
|
|
136
|
+
export const FunctionModel: FunctionModelConstructor;
|
|
137
|
+
export const MapModel: MapModelConstructor;
|
|
138
|
+
export const SetModel: SetModelConstructor;
|