libshv-js 3.2.3 → 3.2.4
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/package.json +1 -1
- package/src/rpcvalue.ts +9 -3
- package/src/zod.ts +2 -1
package/package.json
CHANGED
package/src/rpcvalue.ts
CHANGED
|
@@ -6,6 +6,7 @@ class Int<T = number> {
|
|
|
6
6
|
this.value = u.value;
|
|
7
7
|
return;
|
|
8
8
|
}
|
|
9
|
+
|
|
9
10
|
if (!Number.isInteger(u)) {
|
|
10
11
|
throw new TypeError('Value for Int must a positive integral number');
|
|
11
12
|
}
|
|
@@ -18,10 +19,15 @@ class Int<T = number> {
|
|
|
18
19
|
}
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
class UInt {
|
|
22
|
-
readonly value:
|
|
22
|
+
class UInt<T extends number = number> {
|
|
23
|
+
readonly value: T;
|
|
24
|
+
|
|
25
|
+
constructor(u: T | UInt<T>) {
|
|
26
|
+
if (u instanceof UInt) {
|
|
27
|
+
this.value = u.value;
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
23
30
|
|
|
24
|
-
constructor(u: number) {
|
|
25
31
|
if (u < 0 || !Number.isInteger(u)) {
|
|
26
32
|
throw new Error(`Invalid value '${u}' for UInt must a positive integral number`);
|
|
27
33
|
}
|
package/src/zod.ts
CHANGED
|
@@ -6,6 +6,7 @@ export const recmap = <T extends ZodType<any, any, any>>(schema: T) => z.record(
|
|
|
6
6
|
export const imap = <T extends Record<string, ZodType<any, any, any>>>(schema: T) => z.object(schema).and(z.object({[shvMapType]: z.literal('imap')}));
|
|
7
7
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-arguments -- Zod needs the default argument, otherwise it'll infer as Int<unknown>
|
|
8
8
|
export const int = () => z.instanceof(Int<number>);
|
|
9
|
-
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-arguments -- Zod needs the default argument, otherwise it'll infer as UInt<unknown>
|
|
10
|
+
export const uint = () => z.instanceof(UInt<number>);
|
|
10
11
|
|
|
11
12
|
export * from 'zod';
|