Skip to content

Commit

Permalink
zod: Add UInt
Browse files Browse the repository at this point in the history
  • Loading branch information
syyyr committed Sep 3, 2024
1 parent cf6b8d4 commit 56dc6e3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "libshv-js",
"version": "3.2.0",
"version": "3.2.1",
"description": "Typescript implementation of libshv",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
Expand Down
3 changes: 2 additions & 1 deletion src/zod.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {z, type ZodType} from 'zod';
import {type IMap, Int, isIMap, isShvMap, type RpcValue, type ShvMap} from './rpcvalue';
import {type IMap, Int, isIMap, isShvMap, type RpcValue, type ShvMap, UInt} from './rpcvalue';

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);
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);
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);
export const int = () => z.custom<Int>((data: RpcValue) => data instanceof Int);
export const uint = () => z.custom<UInt>((data: RpcValue) => data instanceof UInt);

export * from 'zod';

0 comments on commit 56dc6e3

Please sign in to comment.