mol_schema 0.0.21 → 0.0.23
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/README.md +17 -15
- package/node.d.ts +406 -165
- package/node.d.ts.map +1 -1
- package/node.deps.json +1 -1
- package/node.js +370 -73
- package/node.js.map +1 -1
- package/node.meta.tree +2 -0
- package/node.mjs +370 -73
- package/node.test.js +615 -255
- package/node.test.js.map +1 -1
- package/package.json +16 -5
- package/web.d.ts +406 -165
- package/web.d.ts.map +1 -1
- package/web.deps.json +1 -1
- package/web.js +370 -73
- package/web.js.map +1 -1
- package/web.meta.tree +2 -0
- package/web.mjs +370 -73
- package/web.test.js +313 -18
- package/web.test.js.map +1 -1
package/README.md
CHANGED
|
@@ -12,51 +12,53 @@
|
|
|
12
12
|
|
|
13
13
|
## Leaf schemas
|
|
14
14
|
|
|
15
|
-
- `$mol_schema_enum(...options)` - some of constant values (first value as default).
|
|
15
|
+
- `$mol_schema_enum([ ...options ])` - some of constant values (first value as default).
|
|
16
16
|
- `$mol_schema_boolean` - true or false (default).
|
|
17
17
|
- `$mol_schema_string` - any string ("" as default).
|
|
18
|
-
- `$mol_schema_pattern(regexp)` - string that matched to regexp ("" as default).
|
|
18
|
+
- `$mol_schema_pattern( regexp )` - string that matched to regexp ("" as default).
|
|
19
19
|
- `$mol_schema_float` - any number (NaN as default).
|
|
20
20
|
- `$mol_schema_integer` - integer number (0 as default).
|
|
21
|
-
- `$
|
|
21
|
+
- `$mol_schema_bigint` - big integer number (0n as default).
|
|
22
|
+
- `$mol_schema_range([ min, max ])` - range of values between min (default) and max.
|
|
22
23
|
- `$mol_schema_positive` - value >= 0
|
|
23
24
|
- `$mol_schema_natural` - natural number from 0 (default).
|
|
24
25
|
- `$mol_schema_negative` - value <= 0
|
|
26
|
+
- `$mol_schema_instance( Class, ...def_args )` - instance of Class.
|
|
25
27
|
|
|
26
28
|
## Composition schemas
|
|
27
29
|
|
|
28
|
-
- `$mol_schema_some(...variants)` - some of schemas (default of first as default).
|
|
30
|
+
- `$mol_schema_some([ ...variants ])` - some of schemas (default of first as default).
|
|
29
31
|
- `$mol_schema_maybe(schema)` - value or null or undefined (undefined as default).
|
|
30
|
-
- `$mol_schema_every(...schemas)` - every of schemas for same value (first default casted through all of them).
|
|
31
|
-
- `$mol_schema_list(item)` - array of same types schema ([] as default).
|
|
32
|
-
- `$mol_schema_dict(key,val)` - key-value dictionary schema ({} as default).
|
|
33
|
-
- `$mol_schema_record({...fields})` - object with typed fields (object with default fields values by default).
|
|
32
|
+
- `$mol_schema_every([ ...schemas ])` - every of schemas for same value (first default casted through all of them).
|
|
33
|
+
- `$mol_schema_list( item )` - array of same types schema ([] as default).
|
|
34
|
+
- `$mol_schema_dict([ key, val ])` - key-value dictionary schema ({} as default).
|
|
35
|
+
- `$mol_schema_record({ ...fields })` - object with typed fields (object with default fields values by default).
|
|
34
36
|
|
|
35
37
|
## Complex example
|
|
36
38
|
|
|
37
39
|
```ts
|
|
38
|
-
export
|
|
40
|
+
export class $my_user_main extends $mol_schema_record({
|
|
39
41
|
name: $mol_schema_string,
|
|
40
42
|
age: $mol_schema_natural,
|
|
41
43
|
}) {}
|
|
42
44
|
|
|
43
|
-
export
|
|
45
|
+
export class $my_user_full extends $mol_schema_record({
|
|
44
46
|
... $my_user_full.Fields,
|
|
45
47
|
bio: $mol_schema_string,
|
|
46
|
-
flags: $mol_schema_dict( $mol_schema_string, $mol_schema_boolean ),
|
|
48
|
+
flags: $mol_schema_dict([ $mol_schema_string, $mol_schema_boolean ]),
|
|
47
49
|
}) {}
|
|
48
50
|
|
|
49
|
-
export
|
|
51
|
+
export class $my_article_full extends $mol_schema_partial({
|
|
50
52
|
title: $mol_schema_string,
|
|
51
53
|
body: $mol_schema_string,
|
|
52
54
|
author: $my_user_full,
|
|
53
55
|
}) {}
|
|
54
56
|
|
|
55
|
-
export
|
|
56
|
-
$
|
|
57
|
+
export class $my_article_search extends $mol_schema_some([
|
|
58
|
+
$mol_schema_record({
|
|
57
59
|
data: $mol_schema_list( $my_article_full ),
|
|
58
60
|
}),
|
|
59
|
-
$
|
|
61
|
+
$mol_schema_record({
|
|
60
62
|
fail: $mol_schema_pattern( /^\w+$/ ),
|
|
61
63
|
}),
|
|
62
64
|
]) {}
|