libshv-js 3.3.0 → 3.3.2
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/rpcmessage.ts +3 -3
- package/src/zod.ts +4 -4
package/package.json
CHANGED
package/src/rpcmessage.ts
CHANGED
|
@@ -142,14 +142,14 @@ class RpcMessage {
|
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
const error_map = this.value[KeyError];
|
|
145
|
-
if (
|
|
145
|
+
if (typeof error_map[ERROR_CODE] !== 'number') {
|
|
146
146
|
return new ProtocolError('Response had an error, but this error did not contain at least an error code');
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
-
const code = error_map[ERROR_CODE];
|
|
149
|
+
const code = error_map[ERROR_CODE] as unknown;
|
|
150
150
|
|
|
151
151
|
const ErrorType = (() => {
|
|
152
|
-
switch (code
|
|
152
|
+
switch (code) {
|
|
153
153
|
case ErrorCode.InvalidRequest: return InvalidRequest;
|
|
154
154
|
case ErrorCode.MethodNotFound: return MethodNotFound;
|
|
155
155
|
case ErrorCode.InvalidParams: return InvalidParams;
|
package/src/zod.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {z, type ZodType} from 'zod';
|
|
2
|
-
import {
|
|
2
|
+
import {type IMap, isIMap, isShvMap, type RpcValue, type ShvMap, UInt} from './rpcvalue';
|
|
3
3
|
|
|
4
|
-
export const map = <T extends Record<string, ZodType<any, any, any>>>(schema: T) => z.
|
|
5
|
-
export const recmap = <T extends ZodType<any, any, any>>(schema: T) => z.
|
|
6
|
-
export const imap = <T extends Record<string, ZodType<any, any, any>>>(schema: T) => z.
|
|
4
|
+
export const map = <T extends Record<string, ZodType<any, any, any>>>(schema: T) => z.custom<ShvMap<{[K in keyof T]: z.infer<T[K]>}>>((data: RpcValue) => isShvMap(data) && z.object(schema).safeParse(data).success);
|
|
5
|
+
export const recmap = <T extends ZodType<any, any, any>>(schema: T) => z.custom<ShvMap<Record<string, z.infer<T>>>>((data: RpcValue) => isShvMap(data) && z.record(z.string(), schema).safeParse(data).success);
|
|
6
|
+
export const imap = <T extends Record<string, ZodType<any, any, any>>>(schema: T) => z.custom<IMap<{[K in keyof T]: z.infer<T[K]>}>>((data: RpcValue) => isIMap(data) && z.object(schema).safeParse(data).success);
|
|
7
7
|
export const int = () => z.number();
|
|
8
8
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-arguments -- Zod needs the default argument, otherwise it'll infer as UInt<unknown>
|
|
9
9
|
export const uint = () => z.instanceof(UInt<number>);
|