lib0 0.2.112 → 0.2.115-0
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 +1 -1
- package/broadcastchannel.js +1 -1
- package/buffer.d.ts +3 -3
- package/buffer.d.ts.map +1 -1
- package/buffer.js +1 -1
- package/coverage/tmp/coverage-27667-1761218530660-0.json +1 -0
- package/coverage/tmp/{coverage-20055-1752683207886-0.json → coverage-27668-1761218485882-0.json} +1 -1
- package/crypto/aes-gcm.d.ts +4 -4
- package/crypto/aes-gcm.d.ts.map +1 -1
- package/crypto/aes-gcm.js +6 -6
- package/crypto/common.d.ts +1 -1
- package/crypto/common.d.ts.map +1 -1
- package/crypto/common.js +1 -1
- package/crypto/ecdsa.d.ts +2 -2
- package/crypto/ecdsa.d.ts.map +1 -1
- package/crypto/ecdsa.js +4 -4
- package/crypto/rsa-oaep.d.ts +2 -2
- package/crypto/rsa-oaep.d.ts.map +1 -1
- package/crypto/rsa-oaep.js +3 -3
- package/decoding.d.ts +27 -14
- package/decoding.d.ts.map +1 -1
- package/decoding.js +12 -8
- package/delta/abstract-array.d.ts +166 -0
- package/delta/abstract-array.d.ts.map +1 -0
- package/delta/abstract-array.js +421 -0
- package/delta/abstract.d.ts +69 -0
- package/delta/abstract.d.ts.map +1 -0
- package/delta/abstract.js +102 -0
- package/delta/array.d.ts +23 -0
- package/delta/array.d.ts.map +1 -0
- package/delta/array.js +45 -0
- package/delta/array.test.d.ts +2 -0
- package/delta/array.test.d.ts.map +1 -0
- package/delta/binding.d.ts +105 -0
- package/delta/binding.d.ts.map +1 -0
- package/delta/binding.js +369 -0
- package/delta/binding.test.d.ts +5 -0
- package/delta/binding.test.d.ts.map +1 -0
- package/delta/d2.d.ts +705 -0
- package/delta/d2.d.ts.map +1 -0
- package/delta/d2.js +1309 -0
- package/delta/d2.test.d.ts +15 -0
- package/delta/d2.test.d.ts.map +1 -0
- package/delta/index.d.ts +14 -0
- package/delta/index.d.ts.map +1 -0
- package/delta/index.js +79 -0
- package/delta/map.d.ts +230 -0
- package/delta/map.d.ts.map +1 -0
- package/delta/map.js +304 -0
- package/delta/node.d.ts +119 -0
- package/delta/node.d.ts.map +1 -0
- package/delta/node.js +183 -0
- package/delta/node.test.d.ts +4 -0
- package/delta/node.test.d.ts.map +1 -0
- package/delta/ops.d.ts +466 -0
- package/delta/ops.d.ts.map +1 -0
- package/delta/ops.js +544 -0
- package/delta/readme.md +129 -0
- package/delta/text.d.ts +43 -0
- package/delta/text.d.ts.map +1 -0
- package/delta/text.js +54 -0
- package/delta/text.test.d.ts +6 -0
- package/delta/text.test.d.ts.map +1 -0
- package/delta/transformer.d.ts +164 -0
- package/delta/transformer.d.ts.map +1 -0
- package/delta/transformer.js +888 -0
- package/delta/transformer.test.d.ts +13 -0
- package/delta/transformer.test.d.ts.map +1 -0
- package/delta/value.d.ts +84 -0
- package/delta/value.d.ts.map +1 -0
- package/delta/value.js +168 -0
- package/dist/abstract-array.cjs +433 -0
- package/dist/abstract-array.cjs.map +1 -0
- package/dist/abstract.cjs +122 -0
- package/dist/abstract.cjs.map +1 -0
- package/dist/aes-gcm.cjs +12 -12
- package/dist/aes-gcm.cjs.map +1 -1
- package/dist/array.cjs +60 -17
- package/dist/array.cjs.map +1 -1
- package/dist/array2.cjs +26 -0
- package/dist/array2.cjs.map +1 -0
- package/dist/binding.cjs +398 -0
- package/dist/binding.cjs.map +1 -0
- package/dist/{broadcastchannel-2c4b0a1c.cjs → broadcastchannel-b4eaea6e.cjs} +4 -4
- package/dist/broadcastchannel-b4eaea6e.cjs.map +1 -0
- package/dist/broadcastchannel.cjs +12 -12
- package/dist/{buffer-a74f7330.cjs → buffer-adc4e6ea.cjs} +7 -7
- package/dist/buffer-adc4e6ea.cjs.map +1 -0
- package/dist/buffer.cjs +11 -11
- package/dist/buffer.d.ts +3 -3
- package/dist/buffer.d.ts.map +1 -1
- package/dist/cache.cjs +6 -6
- package/dist/common.cjs +1 -1
- package/dist/common.cjs.map +1 -1
- package/dist/component.cjs +14 -9
- package/dist/component.cjs.map +1 -1
- package/dist/crypto/aes-gcm.d.ts +4 -4
- package/dist/crypto/aes-gcm.d.ts.map +1 -1
- package/dist/crypto/common.d.ts +1 -1
- package/dist/crypto/common.d.ts.map +1 -1
- package/dist/crypto/ecdsa.d.ts +2 -2
- package/dist/crypto/ecdsa.d.ts.map +1 -1
- package/dist/crypto/rsa-oaep.d.ts +2 -2
- package/dist/crypto/rsa-oaep.d.ts.map +1 -1
- package/dist/d2.cjs +1347 -0
- package/dist/d2.cjs.map +1 -0
- package/dist/{decoding-2b136346.cjs → decoding-50b9ce38.cjs} +18 -14
- package/dist/decoding-50b9ce38.cjs.map +1 -0
- package/dist/decoding.cjs +6 -6
- package/dist/decoding.d.ts +27 -14
- package/dist/decoding.d.ts.map +1 -1
- package/dist/delta/abstract-array.d.ts +166 -0
- package/dist/delta/abstract-array.d.ts.map +1 -0
- package/dist/delta/abstract.d.ts +69 -0
- package/dist/delta/abstract.d.ts.map +1 -0
- package/dist/delta/array.d.ts +23 -0
- package/dist/delta/array.d.ts.map +1 -0
- package/dist/delta/array.test.d.ts +2 -0
- package/dist/delta/array.test.d.ts.map +1 -0
- package/dist/delta/binding.d.ts +105 -0
- package/dist/delta/binding.d.ts.map +1 -0
- package/dist/delta/binding.test.d.ts +5 -0
- package/dist/delta/binding.test.d.ts.map +1 -0
- package/dist/delta/d2.d.ts +705 -0
- package/dist/delta/d2.d.ts.map +1 -0
- package/dist/delta/d2.test.d.ts +15 -0
- package/dist/delta/d2.test.d.ts.map +1 -0
- package/dist/delta/index.d.ts +14 -0
- package/dist/delta/index.d.ts.map +1 -0
- package/dist/delta/map.d.ts +230 -0
- package/dist/delta/map.d.ts.map +1 -0
- package/dist/delta/node.d.ts +119 -0
- package/dist/delta/node.d.ts.map +1 -0
- package/dist/delta/node.test.d.ts +4 -0
- package/dist/delta/node.test.d.ts.map +1 -0
- package/dist/delta/ops.d.ts +466 -0
- package/dist/delta/ops.d.ts.map +1 -0
- package/dist/delta/text.d.ts +43 -0
- package/dist/delta/text.d.ts.map +1 -0
- package/dist/delta/text.test.d.ts +6 -0
- package/dist/delta/text.test.d.ts.map +1 -0
- package/dist/delta/transformer.d.ts +164 -0
- package/dist/delta/transformer.d.ts.map +1 -0
- package/dist/delta/transformer.test.d.ts +13 -0
- package/dist/delta/transformer.test.d.ts.map +1 -0
- package/dist/delta/value.d.ts +84 -0
- package/dist/delta/value.d.ts.map +1 -0
- package/dist/{diff-77c4cf8e.cjs → diff-f0776c15.cjs} +2 -2
- package/dist/{diff-77c4cf8e.cjs.map → diff-f0776c15.cjs.map} +1 -1
- package/dist/diff.cjs +3 -3
- package/dist/{dom-16daf1a0.cjs → dom-2b123630.cjs} +31 -2
- package/dist/dom-2b123630.cjs.map +1 -0
- package/dist/dom.cjs +17 -2
- package/dist/dom.cjs.map +1 -1
- package/dist/dom.d.ts +17 -0
- package/dist/dom.d.ts.map +1 -1
- package/dist/ecdsa.cjs +4 -4
- package/dist/ecdsa.cjs.map +1 -1
- package/dist/{encoding-1acb59c4.cjs → encoding-7f85922c.cjs} +5 -5
- package/dist/encoding-7f85922c.cjs.map +1 -0
- package/dist/encoding.cjs +4 -4
- package/dist/encoding.d.ts +6 -6
- package/dist/encoding.d.ts.map +1 -1
- package/dist/{environment-2de08e0e.cjs → environment-90227ead.cjs} +4 -4
- package/dist/{environment-2de08e0e.cjs.map → environment-90227ead.cjs.map} +1 -1
- package/dist/environment.cjs +5 -5
- package/dist/{error-8582d695.cjs → error-0c1f634f.cjs} +10 -2
- package/dist/error-0c1f634f.cjs.map +1 -0
- package/dist/error.cjs +2 -1
- package/dist/error.cjs.map +1 -1
- package/dist/error.d.ts +1 -0
- package/dist/error.d.ts.map +1 -1
- package/dist/{eventloop-b299a889.cjs → eventloop-a0168106.cjs} +2 -2
- package/dist/{eventloop-b299a889.cjs.map → eventloop-a0168106.cjs.map} +1 -1
- package/dist/eventloop.cjs +3 -3
- package/dist/{function-09b8292c.cjs → function-e7d18feb.cjs} +2 -2
- package/dist/{function-09b8292c.cjs.map → function-e7d18feb.cjs.map} +1 -1
- package/dist/function.cjs +2 -2
- package/dist/index.cjs +23 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index2.cjs +71 -0
- package/dist/index2.cjs.map +1 -0
- package/dist/{indexeddb-0cbb4d6f.cjs → indexeddb-46d1e737.cjs} +3 -3
- package/dist/{indexeddb-0cbb4d6f.cjs.map → indexeddb-46d1e737.cjs.map} +1 -1
- package/dist/indexeddb.cjs +5 -5
- package/dist/indexeddbV2.cjs +2 -1
- package/dist/indexeddbV2.cjs.map +1 -1
- package/dist/jwt.cjs +12 -12
- package/dist/list.cjs +39 -12
- package/dist/list.cjs.map +1 -1
- package/dist/list.d.ts +13 -3
- package/dist/list.d.ts.map +1 -1
- package/dist/logging.cjs +11 -9
- package/dist/logging.cjs.map +1 -1
- package/dist/logging.common.cjs +7 -7
- package/dist/logging.node.cjs +7 -7
- package/dist/{map-0dabcc55.cjs → map-24d263c0.cjs} +7 -1
- package/dist/map-24d263c0.cjs.map +1 -0
- package/dist/map.cjs +314 -7
- package/dist/map.cjs.map +1 -1
- package/dist/map.d.ts +1 -0
- package/dist/map.d.ts.map +1 -1
- package/dist/map2.cjs +15 -0
- package/dist/map2.cjs.map +1 -0
- package/dist/{math-08e068f9.cjs → math-96d5e8c4.cjs} +4 -2
- package/dist/math-96d5e8c4.cjs.map +1 -0
- package/dist/math.cjs +1 -1
- package/dist/math.d.ts.map +1 -1
- package/dist/metric.cjs +1 -1
- package/dist/node.cjs +206 -0
- package/dist/node.cjs.map +1 -0
- package/dist/{number-466d8922.cjs → number-1fb57bba.cjs} +2 -2
- package/dist/{number-466d8922.cjs.map → number-1fb57bba.cjs.map} +1 -1
- package/dist/number.cjs +2 -2
- package/dist/{object-491858d1.cjs → object-18980796.cjs} +12 -2
- package/dist/object-18980796.cjs.map +1 -0
- package/dist/object.cjs +3 -1
- package/dist/object.cjs.map +1 -1
- package/dist/object.d.ts +3 -0
- package/dist/object.d.ts.map +1 -1
- package/dist/observable.cjs +1 -1
- package/dist/ops.cjs +575 -0
- package/dist/ops.cjs.map +1 -0
- package/dist/patience.cjs +2 -2
- package/dist/performance.node.cjs +4 -4
- package/dist/pledge.cjs +2 -1
- package/dist/pledge.cjs.map +1 -1
- package/dist/{prng-24dfe0bf.cjs → prng-004c76e8.cjs} +5 -5
- package/dist/{prng-24dfe0bf.cjs.map → prng-004c76e8.cjs.map} +1 -1
- package/dist/prng.cjs +12 -12
- package/dist/prng.d.ts +1 -1
- package/dist/prng.d.ts.map +1 -1
- package/dist/{promise-7d13a97c.cjs → promise-cda7b9bb.cjs} +2 -2
- package/dist/{promise-7d13a97c.cjs.map → promise-cda7b9bb.cjs.map} +1 -1
- package/dist/promise.cjs +3 -3
- package/dist/rabin-gf2-polynomial.cjs +11 -11
- package/dist/rabin-uncached.cjs +11 -11
- package/dist/rabin.cjs +11 -11
- package/dist/random.cjs +1 -1
- package/dist/rsa-oaep.cjs +3 -3
- package/dist/rsa-oaep.cjs.map +1 -1
- package/dist/schema.cjs +572 -167
- package/dist/schema.cjs.map +1 -1
- package/dist/schema.d.ts +326 -122
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.test.d.ts +5 -0
- package/dist/schema.test.d.ts.map +1 -1
- package/dist/{sort-b8702761.cjs → sort-812cc211.cjs} +2 -2
- package/dist/{sort-b8702761.cjs.map → sort-812cc211.cjs.map} +1 -1
- package/dist/sort.cjs +2 -2
- package/dist/{statistics-c2316dca.cjs → statistics-65f6114b.cjs} +2 -2
- package/dist/{statistics-c2316dca.cjs.map → statistics-65f6114b.cjs.map} +1 -1
- package/dist/statistics.cjs +2 -2
- package/dist/{string-b2827a90.cjs → string-fddc5f8b.cjs} +3 -3
- package/dist/string-fddc5f8b.cjs.map +1 -0
- package/dist/string.cjs +1 -1
- package/dist/string.d.ts +3 -3
- package/dist/string.d.ts.map +1 -1
- package/dist/testing.cjs +16 -16
- package/dist/text.cjs +79 -0
- package/dist/text.cjs.map +1 -0
- package/dist/{time-bc2081b9.cjs → time-d8438852.cjs} +2 -2
- package/dist/{time-bc2081b9.cjs.map → time-d8438852.cjs.map} +1 -1
- package/dist/time.cjs +2 -2
- package/dist/traits.cjs +22 -0
- package/dist/traits.cjs.map +1 -1
- package/dist/traits.d.ts +1 -0
- package/dist/traits.d.ts.map +1 -1
- package/dist/traits.test.d.ts.map +1 -1
- package/dist/transformer.cjs +930 -0
- package/dist/transformer.cjs.map +1 -0
- package/dist/url.cjs +2 -1
- package/dist/url.cjs.map +1 -1
- package/dist/value.cjs +187 -0
- package/dist/value.cjs.map +1 -0
- package/dist/webcrypto.d.ts +1 -1
- package/dist/webcrypto.d.ts.map +1 -1
- package/dist/{websocket-40a601d4.cjs → websocket-b073d0fc.cjs} +3 -3
- package/dist/{websocket-40a601d4.cjs.map → websocket-b073d0fc.cjs.map} +1 -1
- package/dist/websocket.cjs +4 -4
- package/dom.d.ts +17 -0
- package/dom.d.ts.map +1 -1
- package/dom.js +21 -0
- package/encoding.d.ts +6 -6
- package/encoding.d.ts.map +1 -1
- package/encoding.js +1 -1
- package/error.d.ts +1 -0
- package/error.d.ts.map +1 -1
- package/error.js +6 -0
- package/list.d.ts +13 -3
- package/list.d.ts.map +1 -1
- package/list.js +36 -8
- package/map.d.ts +1 -0
- package/map.d.ts.map +1 -1
- package/map.js +6 -0
- package/math.d.ts.map +1 -1
- package/math.js +3 -1
- package/object.d.ts +3 -0
- package/object.d.ts.map +1 -1
- package/object.js +9 -1
- package/package.json +9 -3
- package/prng.d.ts +1 -1
- package/prng.d.ts.map +1 -1
- package/prng.js +1 -1
- package/schema.d.ts +326 -122
- package/schema.d.ts.map +1 -1
- package/schema.js +513 -141
- package/schema.test.d.ts +5 -0
- package/schema.test.d.ts.map +1 -1
- package/string.d.ts +3 -3
- package/string.d.ts.map +1 -1
- package/string.js +2 -2
- package/test.html +1 -0
- package/test.js +13 -1
- package/traits.d.ts +1 -0
- package/traits.d.ts.map +1 -1
- package/traits.js +21 -0
- package/traits.test.d.ts.map +1 -1
- package/webcrypto.d.ts +1 -1
- package/webcrypto.d.ts.map +1 -1
- package/coverage/tmp/coverage-20054-1752683240888-0.json +0 -1
- package/dist/broadcastchannel-2c4b0a1c.cjs.map +0 -1
- package/dist/buffer-a74f7330.cjs.map +0 -1
- package/dist/decoding-2b136346.cjs.map +0 -1
- package/dist/dom-16daf1a0.cjs.map +0 -1
- package/dist/encoding-1acb59c4.cjs.map +0 -1
- package/dist/error-8582d695.cjs.map +0 -1
- package/dist/map-0dabcc55.cjs.map +0 -1
- package/dist/math-08e068f9.cjs.map +0 -1
- package/dist/object-491858d1.cjs.map +0 -1
- package/dist/string-b2827a90.cjs.map +0 -1
package/dist/schema.d.ts
CHANGED
|
@@ -1,7 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @template T
|
|
3
|
+
* @implements {traits.EqualityTrait}
|
|
3
4
|
*/
|
|
4
|
-
export class
|
|
5
|
+
export class Schema<T> implements traits.EqualityTrait {
|
|
6
|
+
/**
|
|
7
|
+
* If true, the more things are added to the shape the more objects this schema will accept (e.g.
|
|
8
|
+
* union). By default, the more objects are added, the the fewer objects this schema will accept.
|
|
9
|
+
* @protected
|
|
10
|
+
*/
|
|
11
|
+
protected static _dilutes: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* @param {Schema<any>} other
|
|
14
|
+
*/
|
|
15
|
+
extends(other: Schema<any>): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Overwrite this when necessary. By default, we only check the `shape` property which every shape
|
|
18
|
+
* should have.
|
|
19
|
+
* @param {Schema<any>} other
|
|
20
|
+
*/
|
|
21
|
+
equals(other: Schema<any>): boolean;
|
|
5
22
|
/**
|
|
6
23
|
* Use `schema.validate(obj)` with a typed parameter that is already of typed to be an instance of
|
|
7
24
|
* Schema. Validate will check the structure of the parameter and return true iff the instance
|
|
@@ -15,17 +32,18 @@ export class $Schema<T> {
|
|
|
15
32
|
* Similar to validate, but this method accepts untyped parameters.
|
|
16
33
|
*
|
|
17
34
|
* @param {any} _o
|
|
35
|
+
* @param {ValidationError} [_err]
|
|
18
36
|
* @return {_o is T}
|
|
19
37
|
*/
|
|
20
|
-
check(_o: any): _o is T;
|
|
38
|
+
check(_o: any, _err?: ValidationError): _o is T;
|
|
21
39
|
/**
|
|
22
|
-
* @type {
|
|
40
|
+
* @type {Schema<T?>}
|
|
23
41
|
*/
|
|
24
|
-
get nullable():
|
|
42
|
+
get nullable(): Schema<T | null>;
|
|
25
43
|
/**
|
|
26
|
-
* @type {$Optional
|
|
44
|
+
* @type {$Optional<Schema<T>>}
|
|
27
45
|
*/
|
|
28
|
-
get optional(): $Optional
|
|
46
|
+
get optional(): $Optional<Schema<T>>;
|
|
29
47
|
/**
|
|
30
48
|
* Cast a variable to a specific type. Returns the casted value, or throws an exception otherwise.
|
|
31
49
|
* Use this if you know that the type is of a specific type and you just want to convince the type
|
|
@@ -34,16 +52,23 @@ export class $Schema<T> {
|
|
|
34
52
|
* **Do not rely on these error messages!**
|
|
35
53
|
* Performs an assertion check only if not in a production environment.
|
|
36
54
|
*
|
|
37
|
-
* @
|
|
38
|
-
* @
|
|
55
|
+
* @template OO
|
|
56
|
+
* @param {OO} o
|
|
57
|
+
* @return {Extract<OO, T> extends never ? T : (OO extends Array<never> ? T : Extract<OO,T>)}
|
|
39
58
|
*/
|
|
40
|
-
cast(o:
|
|
59
|
+
cast<OO>(o: OO): Extract<OO, T> extends never ? T : (OO extends Array<never> ? T : Extract<OO, T>);
|
|
41
60
|
/**
|
|
61
|
+
* EXPECTO PATRONUM!! 🪄
|
|
62
|
+
* This function protects against type errors. Though it may not work in the real world.
|
|
63
|
+
*
|
|
64
|
+
* "After all this time?"
|
|
65
|
+
* "Always." - Snape, talking about type safety
|
|
66
|
+
*
|
|
42
67
|
* Ensures that a variable is a a specific type. Returns the value, or throws an exception if the assertion check failed.
|
|
43
68
|
* Use this if you know that the type is of a specific type and you just want to convince the type
|
|
44
69
|
* system.
|
|
45
70
|
*
|
|
46
|
-
* Can be useful when defining lambdas: `s.lambda(s.$number, s.$void).
|
|
71
|
+
* Can be useful when defining lambdas: `s.lambda(s.$number, s.$void).expect((n) => n + 1)`
|
|
47
72
|
*
|
|
48
73
|
* **Do not rely on these error messages!**
|
|
49
74
|
* Performs an assertion check if not in a production environment.
|
|
@@ -51,150 +76,261 @@ export class $Schema<T> {
|
|
|
51
76
|
* @param {T} o
|
|
52
77
|
* @return {o extends T ? T : never}
|
|
53
78
|
*/
|
|
54
|
-
|
|
55
|
-
|
|
79
|
+
expect(o: T): T extends T ? T : never;
|
|
80
|
+
[schemaSymbol](): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* @param {object} other
|
|
83
|
+
*/
|
|
84
|
+
[traits.EqualityTraitSymbol](other: object): boolean;
|
|
56
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* @template {(new (...args:any[]) => any) | ((...args:any[]) => any)} Constr
|
|
88
|
+
* @typedef {Constr extends ((...args:any[]) => infer T) ? T : (Constr extends (new (...args:any[]) => any) ? InstanceType<Constr> : never)} Instance
|
|
89
|
+
*/
|
|
57
90
|
/**
|
|
58
91
|
* @template {(new (...args:any[]) => any) | ((...args:any[]) => any)} C
|
|
59
|
-
* @extends {
|
|
92
|
+
* @extends {Schema<Instance<C>>}
|
|
60
93
|
*/
|
|
61
|
-
export class $ConstructedBy<C extends (new (...args: any[]) => any) | ((...args: any[]) => any)> extends
|
|
94
|
+
export class $ConstructedBy<C extends (new (...args: any[]) => any) | ((...args: any[]) => any)> extends Schema<Instance<C>> {
|
|
62
95
|
/**
|
|
63
96
|
* @param {C} c
|
|
97
|
+
* @param {((o:Instance<C>)=>boolean)|null} check
|
|
64
98
|
*/
|
|
65
|
-
constructor(c: C);
|
|
66
|
-
|
|
99
|
+
constructor(c: C, check: ((o: Instance<C>) => boolean) | null);
|
|
100
|
+
shape: C;
|
|
101
|
+
_c: ((o: Instance<C>) => boolean) | null;
|
|
67
102
|
/**
|
|
68
103
|
* @param {any} o
|
|
104
|
+
* @param {ValidationError} [err]
|
|
69
105
|
* @return {o is C extends ((...args:any[]) => infer T) ? T : (C extends (new (...args:any[]) => any) ? InstanceType<C> : never)} o
|
|
70
106
|
*/
|
|
71
|
-
check(o: any): o is C extends ((...args: any[]) => infer
|
|
107
|
+
check(o: any, err?: ValidationError): o is C extends ((...args: any[]) => infer T) ? T : (C extends (new (...args: any[]) => any) ? InstanceType<C> : never);
|
|
108
|
+
}
|
|
109
|
+
export function $constructedBy<C extends (new (...args: any[]) => any) | ((...args: any[]) => any)>(c: C, check?: ((o: Instance<C>) => boolean) | null): CastToSchema<$ConstructedBy<C>>;
|
|
110
|
+
export const $$constructedBy: Schema<$ConstructedBy<(new (...args: any[]) => any) | ((...args: any[]) => any)>>;
|
|
111
|
+
/**
|
|
112
|
+
* Check custom properties on any object. You may want to overwrite the generated Schema<any>.
|
|
113
|
+
*
|
|
114
|
+
* @extends {Schema<any>}
|
|
115
|
+
*/
|
|
116
|
+
export class $Custom extends Schema<any> {
|
|
117
|
+
/**
|
|
118
|
+
* @param {(o:any) => boolean} check
|
|
119
|
+
*/
|
|
120
|
+
constructor(check: (o: any) => boolean);
|
|
121
|
+
/**
|
|
122
|
+
* @type {(o:any) => boolean}
|
|
123
|
+
*/
|
|
124
|
+
shape: (o: any) => boolean;
|
|
125
|
+
/**
|
|
126
|
+
* @param {any} o
|
|
127
|
+
* @param {ValidationError} err
|
|
128
|
+
* @return {o is any}
|
|
129
|
+
*/
|
|
130
|
+
check(o: any, err: ValidationError): o is any;
|
|
72
131
|
}
|
|
73
|
-
export function
|
|
132
|
+
export function $custom(check: (o: any) => boolean): Schema<any>;
|
|
133
|
+
export const $$custom: Schema<$Custom>;
|
|
74
134
|
/**
|
|
75
135
|
* @template {LiteralType} T
|
|
76
|
-
* @extends {
|
|
136
|
+
* @extends {Schema<T>}
|
|
77
137
|
*/
|
|
78
|
-
export class $Literal<T extends LiteralType> extends
|
|
138
|
+
export class $Literal<T extends LiteralType> extends Schema<T> {
|
|
79
139
|
/**
|
|
80
140
|
* @param {Array<T>} literals
|
|
81
141
|
*/
|
|
82
142
|
constructor(literals: Array<T>);
|
|
83
|
-
|
|
143
|
+
shape: T[];
|
|
84
144
|
}
|
|
85
|
-
export function literal<T extends LiteralType[]>(...literals: T): CastToSchema<$Literal<T[number]>>;
|
|
145
|
+
export function $literal<T extends LiteralType[]>(...literals: T): CastToSchema<$Literal<T[number]>>;
|
|
146
|
+
export const $$literal: Schema<$Literal<LiteralType>>;
|
|
86
147
|
/**
|
|
87
|
-
* @template {
|
|
88
|
-
* @
|
|
148
|
+
* @template {Array<string|Schema<string|number>>} T
|
|
149
|
+
* @extends {Schema<CastStringTemplateArgsToTemplate<T>>}
|
|
89
150
|
*/
|
|
151
|
+
export class $StringTemplate<T extends Array<string | Schema<string | number>>> extends Schema<CastStringTemplateArgsToTemplate<T>> {
|
|
152
|
+
/**
|
|
153
|
+
* @param {T} shape
|
|
154
|
+
*/
|
|
155
|
+
constructor(shape: T);
|
|
156
|
+
shape: T;
|
|
157
|
+
_r: RegExp;
|
|
158
|
+
}
|
|
159
|
+
export function $stringTemplate<T extends Array<string | Schema<string | number>>>(...literals: T): CastToSchema<$StringTemplate<T>>;
|
|
160
|
+
export const $$stringTemplate: Schema<$StringTemplate<(string | Schema<string | number>)[]>>;
|
|
161
|
+
export const $$optional: Schema<$Optional<Schema<any>>>;
|
|
90
162
|
/**
|
|
91
|
-
* @
|
|
92
|
-
|
|
163
|
+
* @type {Schema<never>}
|
|
164
|
+
*/
|
|
165
|
+
export const $never: Schema<never>;
|
|
166
|
+
export const $$never: Schema<$Never>;
|
|
167
|
+
/**
|
|
168
|
+
* @template {{ [key: string|symbol|number]: Schema<any> }} S
|
|
169
|
+
* @typedef {{ [Key in keyof S as S[Key] extends $Optional<Schema<any>> ? Key : never]?: S[Key] extends $Optional<Schema<infer Type>> ? Type : never } & { [Key in keyof S as S[Key] extends $Optional<Schema<any>> ? never : Key]: S[Key] extends Schema<infer Type> ? Type : never }} $ObjectToType
|
|
170
|
+
*/
|
|
171
|
+
/**
|
|
172
|
+
* @template {{[key:string|symbol|number]: Schema<any>}} S
|
|
173
|
+
* @extends {Schema<$ObjectToType<S>>}
|
|
93
174
|
*/
|
|
94
175
|
export class $Object<S extends {
|
|
95
|
-
[key: string | symbol | number]:
|
|
96
|
-
}> extends
|
|
176
|
+
[key: string | symbol | number]: Schema<any>;
|
|
177
|
+
}> extends Schema<$ObjectToType<S>> {
|
|
178
|
+
/**
|
|
179
|
+
* @param {S} shape
|
|
180
|
+
* @param {boolean} partial
|
|
181
|
+
*/
|
|
182
|
+
constructor(shape: S, partial?: boolean);
|
|
183
|
+
/**
|
|
184
|
+
* @type {S}
|
|
185
|
+
*/
|
|
186
|
+
shape: S;
|
|
187
|
+
_isPartial: boolean;
|
|
188
|
+
/**
|
|
189
|
+
* @type {Schema<Partial<$ObjectToType<S>>>}
|
|
190
|
+
*/
|
|
191
|
+
get partial(): Schema<Partial<$ObjectToType<S>>>;
|
|
97
192
|
/**
|
|
98
|
-
* @param {
|
|
193
|
+
* @param {any} o
|
|
194
|
+
* @param {ValidationError} err
|
|
195
|
+
* @return {o is $ObjectToType<S>}
|
|
99
196
|
*/
|
|
100
|
-
|
|
101
|
-
v: S;
|
|
197
|
+
check(o: any, err: ValidationError): o is $ObjectToType<S>;
|
|
102
198
|
}
|
|
103
|
-
export function object<S extends {
|
|
104
|
-
[key: string | symbol | number]:
|
|
105
|
-
}>(def: S):
|
|
199
|
+
export function $object<S extends {
|
|
200
|
+
[key: string | symbol | number]: Schema<any>;
|
|
201
|
+
}>(def: S): _ObjectDefToSchema<S> extends Schema<infer S_1> ? Schema<S_1> : never;
|
|
202
|
+
export const $$object: Schema<$Object<{
|
|
203
|
+
[key: string]: Schema<any>;
|
|
204
|
+
[key: number]: Schema<any>;
|
|
205
|
+
[key: symbol]: Schema<any>;
|
|
206
|
+
}>>;
|
|
207
|
+
/**
|
|
208
|
+
* @type {Schema<{[key:string]: any}>}
|
|
209
|
+
*/
|
|
210
|
+
export const $objectAny: Schema<{
|
|
211
|
+
[key: string]: any;
|
|
212
|
+
}>;
|
|
106
213
|
/**
|
|
107
|
-
* @template {
|
|
108
|
-
* @template {
|
|
109
|
-
* @extends {
|
|
214
|
+
* @template {Schema<string|number|symbol>} Keys
|
|
215
|
+
* @template {Schema<any>} Values
|
|
216
|
+
* @extends {Schema<{ [key in Unwrap<Keys>]: Unwrap<Values> }>}
|
|
110
217
|
*/
|
|
111
|
-
export class $Record<Keys extends
|
|
218
|
+
export class $Record<Keys extends Schema<string | number | symbol>, Values extends Schema<any>> extends Schema<{ [key in Unwrap<Keys>]: Unwrap<Values>; }> {
|
|
112
219
|
/**
|
|
113
220
|
* @param {Keys} keys
|
|
114
221
|
* @param {Values} values
|
|
115
222
|
*/
|
|
116
223
|
constructor(keys: Keys, values: Values);
|
|
117
|
-
|
|
118
|
-
|
|
224
|
+
shape: {
|
|
225
|
+
keys: Keys;
|
|
226
|
+
values: Values;
|
|
227
|
+
};
|
|
119
228
|
/**
|
|
120
229
|
* @param {any} o
|
|
121
|
-
* @
|
|
230
|
+
* @param {ValidationError} err
|
|
231
|
+
* @return {o is { [key in Unwrap<Keys>]: Unwrap<Values> }}
|
|
122
232
|
*/
|
|
123
|
-
check(o: any): o is
|
|
233
|
+
check(o: any, err: ValidationError): o is { [key_1 in Unwrap<Keys>]: Unwrap<Values>; };
|
|
124
234
|
}
|
|
125
|
-
export function record<Keys extends
|
|
235
|
+
export function $record<Keys extends Schema<string | number | symbol>, Values extends Schema<any>>(keys: Keys, values: Values): CastToSchema<$Record<Keys, Values>>;
|
|
236
|
+
export const $$record: Schema<$Record<Schema<string | number | symbol>, Schema<any>>>;
|
|
126
237
|
/**
|
|
127
|
-
* @template {
|
|
128
|
-
* @extends {
|
|
238
|
+
* @template {Schema<any>[]} S
|
|
239
|
+
* @extends {Schema<{ [Key in keyof S]: S[Key] extends Schema<infer Type> ? Type : never }>}
|
|
129
240
|
*/
|
|
130
|
-
export class $Tuple<S extends
|
|
241
|
+
export class $Tuple<S extends Schema<any>[]> extends Schema<{ [Key in keyof S]: S[Key] extends Schema<infer Type> ? Type : never; }> {
|
|
131
242
|
/**
|
|
132
|
-
* @param {S}
|
|
243
|
+
* @param {S} shape
|
|
133
244
|
*/
|
|
134
|
-
constructor(
|
|
135
|
-
|
|
245
|
+
constructor(shape: S);
|
|
246
|
+
shape: S;
|
|
136
247
|
/**
|
|
137
248
|
* @param {any} o
|
|
138
|
-
* @
|
|
249
|
+
* @param {ValidationError} err
|
|
250
|
+
* @return {o is { [K in keyof S]: S[K] extends Schema<infer Type> ? Type : never }}
|
|
139
251
|
*/
|
|
140
|
-
check(o: any): o is { [K in keyof S]: S[K] extends
|
|
252
|
+
check(o: any, err: ValidationError): o is { [K in keyof S]: S[K] extends Schema<infer Type> ? Type : never; };
|
|
141
253
|
}
|
|
142
|
-
export function tuple<T extends Array
|
|
254
|
+
export function $tuple<T extends Array<Schema<any>>>(...def: T): CastToSchema<$Tuple<T>>;
|
|
255
|
+
export const $$tuple: Schema<$Tuple<Schema<any>[]>>;
|
|
143
256
|
/**
|
|
144
|
-
* @template {
|
|
145
|
-
* @extends {
|
|
257
|
+
* @template {Schema<any>} S
|
|
258
|
+
* @extends {Schema<Array<S extends Schema<infer T> ? T : never>>}
|
|
146
259
|
*/
|
|
147
|
-
export class $Array<S extends
|
|
260
|
+
export class $Array<S extends Schema<any>> extends Schema<(S extends Schema<infer T> ? T : never)[]> {
|
|
148
261
|
/**
|
|
149
262
|
* @param {Array<S>} v
|
|
150
263
|
*/
|
|
151
264
|
constructor(v: Array<S>);
|
|
152
265
|
/**
|
|
153
|
-
* @type {
|
|
266
|
+
* @type {Schema<S extends Schema<infer T> ? T : never>}
|
|
154
267
|
*/
|
|
155
|
-
|
|
268
|
+
shape: Schema<S extends Schema<infer T_1> ? T_1 : never>;
|
|
156
269
|
/**
|
|
157
270
|
* @param {any} o
|
|
158
|
-
* @
|
|
271
|
+
* @param {ValidationError} [err]
|
|
272
|
+
* @return {o is Array<S extends Schema<infer T> ? T : never>} o
|
|
159
273
|
*/
|
|
160
|
-
check(o: any): o is Array<S extends
|
|
274
|
+
check(o: any, err?: ValidationError): o is Array<S extends Schema<infer T_1> ? T_1 : never>;
|
|
161
275
|
}
|
|
162
|
-
export function array<T extends Array
|
|
276
|
+
export function $array<T extends Array<Schema<any>>>(...def: T): Schema<Array<T extends Array<Schema<infer S>> ? S : never>>;
|
|
277
|
+
export const $$array: Schema<$Array<Schema<any>>>;
|
|
278
|
+
/**
|
|
279
|
+
* @type {Schema<Array<any>>}
|
|
280
|
+
*/
|
|
281
|
+
export const $arrayAny: Schema<Array<any>>;
|
|
163
282
|
/**
|
|
164
283
|
* @template T
|
|
165
|
-
* @extends {
|
|
284
|
+
* @extends {Schema<T>}
|
|
166
285
|
*/
|
|
167
|
-
export class $InstanceOf<T> extends
|
|
286
|
+
export class $InstanceOf<T> extends Schema<T> {
|
|
168
287
|
/**
|
|
169
288
|
* @param {new (...args:any) => T} constructor
|
|
289
|
+
* @param {((o:T) => boolean)|null} check
|
|
170
290
|
*/
|
|
171
|
-
constructor(constructor: new (...args: any) => T);
|
|
172
|
-
|
|
291
|
+
constructor(constructor: new (...args: any) => T, check: ((o: T) => boolean) | null);
|
|
292
|
+
shape: new (...args: any) => T;
|
|
293
|
+
_c: ((o: T) => boolean) | null;
|
|
294
|
+
/**
|
|
295
|
+
* @param {any} o
|
|
296
|
+
* @param {ValidationError} err
|
|
297
|
+
* @return {o is T}
|
|
298
|
+
*/
|
|
299
|
+
check(o: any, err: ValidationError): o is T;
|
|
173
300
|
}
|
|
174
|
-
export function
|
|
301
|
+
export function $instanceOf<T>(c: new (...args: any) => T, check?: ((o: T) => boolean) | null): Schema<T>;
|
|
302
|
+
export const $$instanceOf: Schema<$InstanceOf<unknown>>;
|
|
303
|
+
export const $$schema: Schema<Schema<unknown>>;
|
|
175
304
|
/**
|
|
176
|
-
* @template {
|
|
305
|
+
* @template {Schema<any>[]} Args
|
|
177
306
|
* @typedef {(...args:UnwrapArray<TuplePop<Args>>)=>Unwrap<TupleLast<Args>>} _LArgsToLambdaDef
|
|
178
307
|
*/
|
|
179
308
|
/**
|
|
180
|
-
* @template {Array
|
|
181
|
-
* @extends {
|
|
309
|
+
* @template {Array<Schema<any>>} Args
|
|
310
|
+
* @extends {Schema<_LArgsToLambdaDef<Args>>}
|
|
182
311
|
*/
|
|
183
|
-
export class $Lambda<Args extends Array
|
|
312
|
+
export class $Lambda<Args extends Array<Schema<any>>> extends Schema<_LArgsToLambdaDef<Args>> {
|
|
184
313
|
/**
|
|
185
314
|
* @param {Args} args
|
|
186
315
|
*/
|
|
187
316
|
constructor(args: Args);
|
|
188
317
|
len: number;
|
|
189
|
-
args:
|
|
190
|
-
res:
|
|
318
|
+
args: Schema<any[]>;
|
|
319
|
+
res: Schema<any>;
|
|
320
|
+
/**
|
|
321
|
+
* @param {any} f
|
|
322
|
+
* @param {ValidationError} err
|
|
323
|
+
* @return {f is _LArgsToLambdaDef<Args>}
|
|
324
|
+
*/
|
|
325
|
+
check(f: any, err: ValidationError): f is _LArgsToLambdaDef<Args>;
|
|
191
326
|
}
|
|
192
|
-
export function lambda<Args extends
|
|
327
|
+
export function $lambda<Args extends Schema<any>[]>(...args: Args): Schema<(...args: UnwrapArray<TuplePop<Args>>) => Unwrap<TupleLast<Args>>>;
|
|
328
|
+
export const $$lambda: Schema<$Lambda<Schema<any>[]>>;
|
|
193
329
|
/**
|
|
194
|
-
* @template {Array
|
|
195
|
-
* @extends {
|
|
330
|
+
* @template {Array<Schema<any>>} T
|
|
331
|
+
* @extends {Schema<Intersect<UnwrapArray<T>>>}
|
|
196
332
|
*/
|
|
197
|
-
export class $Intersection<T extends Array
|
|
333
|
+
export class $Intersection<T extends Array<Schema<any>>> extends Schema<Intersect<UnwrapArray<T>>> {
|
|
198
334
|
/**
|
|
199
335
|
* @param {T} v
|
|
200
336
|
*/
|
|
@@ -202,73 +338,143 @@ export class $Intersection<T extends Array<$Schema<any>>> extends $Schema<Inters
|
|
|
202
338
|
/**
|
|
203
339
|
* @type {T}
|
|
204
340
|
*/
|
|
205
|
-
|
|
341
|
+
shape: T;
|
|
206
342
|
}
|
|
207
|
-
export function intersect<T extends
|
|
343
|
+
export function $intersect<T extends Schema<any>[]>(...def: T): CastToSchema<$Intersection<T>>;
|
|
344
|
+
export const $$intersect: Schema<$Intersection<Schema<any>[]>>;
|
|
208
345
|
/**
|
|
209
346
|
* @template S
|
|
210
|
-
* @extends {
|
|
347
|
+
* @extends {Schema<S>}
|
|
211
348
|
*/
|
|
212
|
-
export class $Union<S> extends
|
|
213
|
-
static schema: $Schema<$Union<unknown>>;
|
|
349
|
+
export class $Union<S> extends Schema<S> {
|
|
214
350
|
/**
|
|
215
|
-
* @param {Array
|
|
351
|
+
* @param {Array<Schema<S>>} v
|
|
216
352
|
*/
|
|
217
|
-
constructor(v: Array
|
|
218
|
-
|
|
353
|
+
constructor(v: Array<Schema<S>>);
|
|
354
|
+
shape: Schema<S>[];
|
|
219
355
|
}
|
|
220
|
-
export function union<T extends Array
|
|
356
|
+
export function $union<T extends Array<Schema<any>>>(...schemas: T): CastToSchema<$Union<T extends [] ? never : (T extends Array<Schema<infer S>> ? S : never)>>;
|
|
357
|
+
export const $$union: Schema<$Union<any>>;
|
|
358
|
+
/**
|
|
359
|
+
* @type {Schema<any>}
|
|
360
|
+
*/
|
|
361
|
+
export const $any: Schema<any>;
|
|
362
|
+
export const $$any: Schema<Schema<any>>;
|
|
363
|
+
/**
|
|
364
|
+
* @type {Schema<bigint>}
|
|
365
|
+
*/
|
|
366
|
+
export const $bigint: Schema<bigint>;
|
|
367
|
+
export const $$bigint: Schema<Schema<bigint>>;
|
|
368
|
+
/**
|
|
369
|
+
* @type {Schema<Symbol>}
|
|
370
|
+
*/
|
|
371
|
+
export const $symbol: Schema<Symbol>;
|
|
372
|
+
export const $$symbol: Schema<Schema<Symbol>>;
|
|
373
|
+
/**
|
|
374
|
+
* @type {Schema<number>}
|
|
375
|
+
*/
|
|
376
|
+
export const $number: Schema<number>;
|
|
377
|
+
export const $$number: Schema<Schema<number>>;
|
|
378
|
+
/**
|
|
379
|
+
* @type {Schema<string>}
|
|
380
|
+
*/
|
|
381
|
+
export const $string: Schema<string>;
|
|
382
|
+
export const $$string: Schema<Schema<string>>;
|
|
383
|
+
/**
|
|
384
|
+
* @type {Schema<boolean>}
|
|
385
|
+
*/
|
|
386
|
+
export const $boolean: Schema<boolean>;
|
|
387
|
+
export const $$boolean: Schema<Schema<boolean>>;
|
|
388
|
+
/**
|
|
389
|
+
* @type {Schema<undefined>}
|
|
390
|
+
*/
|
|
391
|
+
export const $undefined: Schema<undefined>;
|
|
392
|
+
export const $$undefined: Schema<Schema<undefined>>;
|
|
221
393
|
/**
|
|
222
|
-
* @type {
|
|
394
|
+
* @type {Schema<void>}
|
|
223
395
|
*/
|
|
224
|
-
export const
|
|
396
|
+
export const $void: Schema<void>;
|
|
397
|
+
export const $$void: Schema<Schema<void>>;
|
|
398
|
+
export const $null: Schema<null>;
|
|
399
|
+
export const $$null: Schema<Schema<null>>;
|
|
225
400
|
/**
|
|
226
|
-
* @type {
|
|
401
|
+
* @type {Schema<number|string|null|boolean>}
|
|
227
402
|
*/
|
|
228
|
-
export const
|
|
403
|
+
export const $primitive: Schema<number | string | null | boolean>;
|
|
229
404
|
/**
|
|
230
|
-
* @
|
|
405
|
+
* @typedef {JSON[]} JSONArray
|
|
231
406
|
*/
|
|
232
|
-
export const symbol: $Schema<Symbol>;
|
|
233
407
|
/**
|
|
234
|
-
* @
|
|
408
|
+
* @typedef {Unwrap<$primitive>|JSONArray|{ [key:string]:JSON }} JSON
|
|
235
409
|
*/
|
|
236
|
-
export const number: $Schema<number>;
|
|
237
410
|
/**
|
|
238
|
-
* @type {
|
|
411
|
+
* @type {Schema<null|number|string|boolean|JSON[]|{[key:string]:JSON}>}
|
|
239
412
|
*/
|
|
240
|
-
export const
|
|
413
|
+
export const $json: Schema<null | number | string | boolean | JSON[] | {
|
|
414
|
+
[key: string]: JSON;
|
|
415
|
+
}>;
|
|
241
416
|
/**
|
|
242
417
|
* Assert that a variable is of this specific type.
|
|
243
418
|
* The assertion check is only performed in non-production environments.
|
|
244
419
|
*
|
|
245
|
-
* @type {<T>(o:any,schema
|
|
420
|
+
* @type {<T>(o:any,schema:Schema<T>) => asserts o is T}
|
|
246
421
|
*/
|
|
247
|
-
export const assert: <T>(o: any, schema:
|
|
422
|
+
export const assert: <T>(o: any, schema: Schema<T>) => asserts o is T;
|
|
248
423
|
export type LiteralType = string | number | bigint | boolean | null | undefined;
|
|
249
424
|
export type AnyObject = {
|
|
250
425
|
[k: string | number | symbol]: any;
|
|
251
426
|
};
|
|
252
|
-
export type Unwrap<T> = T extends
|
|
253
|
-
export type
|
|
254
|
-
export type
|
|
427
|
+
export type Unwrap<T> = T extends Schema<infer X> ? X : T;
|
|
428
|
+
export type TypeOf<T> = T extends Schema<infer X> ? X : T;
|
|
429
|
+
export type UnwrapArray<T extends readonly unknown[]> = T extends readonly [Schema<infer First>, ...infer Rest] ? [First, ...UnwrapArray<Rest>] : [];
|
|
430
|
+
export type CastToSchema<T> = T extends Schema<infer S> ? Schema<S> : never;
|
|
255
431
|
export type TupleLast<Arr extends unknown[]> = Arr extends [...unknown[], infer L] ? L : never;
|
|
256
432
|
export type TuplePop<Arr extends unknown[]> = Arr extends [...infer Fs, unknown] ? Fs : never;
|
|
257
433
|
export type Intersect<T extends readonly unknown[]> = T extends [] ? {} : T extends [infer First] ? First : T extends [infer First, ...infer Rest] ? First & Intersect<Rest> : never;
|
|
434
|
+
export type Instance<Constr extends (new (...args: any[]) => any) | ((...args: any[]) => any)> = Constr extends ((...args: any[]) => infer T) ? T : (Constr extends (new (...args: any[]) => any) ? InstanceType<Constr> : never);
|
|
435
|
+
export type CastStringTemplateArgsToTemplate<Ts extends Array<string | Schema<string | number>>> = Ts extends [] ? `` : (Ts extends [infer T] ? (Unwrap<T> extends (string | number) ? Unwrap<T> : never) : (Ts extends [infer T1, ...infer Rest] ? `${Unwrap<T1> extends (string | number) ? Unwrap<T1> : never}${Rest extends Array<string | Schema<string | number>> ? CastStringTemplateArgsToTemplate<Rest> : never}` : never));
|
|
258
436
|
export type $ObjectToType<S extends {
|
|
259
|
-
[key: string | symbol | number]:
|
|
260
|
-
}> = { [Key in keyof S as S[Key] extends $Optional
|
|
261
|
-
export type
|
|
437
|
+
[key: string | symbol | number]: Schema<any>;
|
|
438
|
+
}> = { [Key in keyof S as S[Key] extends $Optional<Schema<any>> ? Key : never]?: S[Key] extends $Optional<Schema<infer Type>> ? Type : never; } & { [Key in keyof S as S[Key] extends $Optional<Schema<any>> ? never : Key]: S[Key] extends Schema<infer Type> ? Type : never; };
|
|
439
|
+
export type _ObjectDefToSchema<S extends {
|
|
440
|
+
[key: string | symbol | number]: Schema<any>;
|
|
441
|
+
}> = Schema<{ [Key in keyof S as S[Key] extends $Optional<Schema<any>> ? Key : never]?: S[Key] extends $Optional<Schema<infer Type>> ? Type : never; } & { [Key in keyof S as S[Key] extends $Optional<Schema<any>> ? never : Key]: S[Key] extends Schema<infer Type> ? Type : never; }>;
|
|
442
|
+
export type _LArgsToLambdaDef<Args extends Schema<any>[]> = (...args: UnwrapArray<TuplePop<Args>>) => Unwrap<TupleLast<Args>>;
|
|
443
|
+
export type JSONArray = JSON[];
|
|
444
|
+
export type JSON = Unwrap<Schema<string | number | boolean | null>> | JSONArray | {
|
|
445
|
+
[key: string]: JSON;
|
|
446
|
+
};
|
|
447
|
+
import * as traits from './traits.js';
|
|
448
|
+
declare class ValidationError {
|
|
449
|
+
/**
|
|
450
|
+
* Reverse errors
|
|
451
|
+
* @type {Array<{ path: string?, expected: string, has: string, message: string? }>}
|
|
452
|
+
*/
|
|
453
|
+
_rerrs: Array<{
|
|
454
|
+
path: string | null;
|
|
455
|
+
expected: string;
|
|
456
|
+
has: string;
|
|
457
|
+
message: string | null;
|
|
458
|
+
}>;
|
|
459
|
+
/**
|
|
460
|
+
* @param {string?} path
|
|
461
|
+
* @param {string} expected
|
|
462
|
+
* @param {string} has
|
|
463
|
+
* @param {string?} message
|
|
464
|
+
*/
|
|
465
|
+
extend(path: string | null, expected: string, has: string, message?: string | null): void;
|
|
466
|
+
toString(): string;
|
|
467
|
+
}
|
|
262
468
|
/**
|
|
263
|
-
* @template {
|
|
264
|
-
* @extends
|
|
469
|
+
* @template {Schema<any>} S
|
|
470
|
+
* @extends Schema<Unwrap<S>|undefined>
|
|
265
471
|
*/
|
|
266
|
-
declare class $Optional<S extends
|
|
472
|
+
declare class $Optional<S extends Schema<any>> extends Schema<Unwrap<S> | undefined> {
|
|
267
473
|
/**
|
|
268
|
-
* @param {S}
|
|
474
|
+
* @param {S} shape
|
|
269
475
|
*/
|
|
270
|
-
constructor(
|
|
271
|
-
|
|
476
|
+
constructor(shape: S);
|
|
477
|
+
shape: S;
|
|
272
478
|
get [isOptionalSymbol](): boolean;
|
|
273
479
|
}
|
|
274
480
|
/**
|
|
@@ -279,15 +485,19 @@ declare class $Optional<S extends $Schema<any>> extends $Schema<Unwrap<S> | unde
|
|
|
279
485
|
*/
|
|
280
486
|
/**
|
|
281
487
|
* @template T
|
|
282
|
-
* @typedef {T extends
|
|
488
|
+
* @typedef {T extends Schema<infer X> ? X : T} Unwrap
|
|
489
|
+
*/
|
|
490
|
+
/**
|
|
491
|
+
* @template T
|
|
492
|
+
* @typedef {T extends Schema<infer X> ? X : T} TypeOf
|
|
283
493
|
*/
|
|
284
494
|
/**
|
|
285
495
|
* @template {readonly unknown[]} T
|
|
286
|
-
* @typedef {T extends readonly [
|
|
496
|
+
* @typedef {T extends readonly [Schema<infer First>, ...infer Rest] ? [First, ...UnwrapArray<Rest>] : [] } UnwrapArray
|
|
287
497
|
*/
|
|
288
498
|
/**
|
|
289
499
|
* @template T
|
|
290
|
-
* @typedef {T extends
|
|
500
|
+
* @typedef {T extends Schema<infer S> ? Schema<S> : never} CastToSchema
|
|
291
501
|
*/
|
|
292
502
|
/**
|
|
293
503
|
* @template {unknown[]} Arr
|
|
@@ -310,17 +520,11 @@ declare class $Optional<S extends $Schema<any>> extends $Schema<Unwrap<S> | unde
|
|
|
310
520
|
*/
|
|
311
521
|
declare const schemaSymbol: unique symbol;
|
|
312
522
|
/**
|
|
313
|
-
* @
|
|
523
|
+
* @extends Schema<never>
|
|
314
524
|
*/
|
|
315
|
-
declare
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
*/
|
|
319
|
-
declare const void_: $Schema<void>;
|
|
320
|
-
/**
|
|
321
|
-
* @type {$Schema<undefined>}
|
|
322
|
-
*/
|
|
323
|
-
declare const undefined_: $Schema<undefined>;
|
|
525
|
+
declare class $Never extends Schema<never> {
|
|
526
|
+
constructor();
|
|
527
|
+
}
|
|
324
528
|
declare const isOptionalSymbol: unique symbol;
|
|
325
|
-
export {
|
|
529
|
+
export {};
|
|
326
530
|
//# sourceMappingURL=schema.d.ts.map
|