Skip to content

Commit

Permalink
zod: Add support for double/decimal/blob
Browse files Browse the repository at this point in the history
  • Loading branch information
syyyr committed Oct 22, 2024
1 parent e6fa7ae commit 9183777
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 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.4.0",
"version": "3.4.1",
"description": "Typescript implementation of libshv",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
Expand Down
9 changes: 6 additions & 3 deletions src/zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@ export const metamap = <T extends Record<string | number, ZodType<any, any, any>
export const int = () => z.number();
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-arguments -- Zod needs the default argument, otherwise it'll infer as UInt<unknown>
export const uint = () => z.instanceof(UInt<number>);
export const double = () => z.instanceof(Double);
export const decimal = () => z.instanceof(Decimal);
export const blob = () => z.instanceof(ArrayBuffer);

const withMetaInstanceParser = z.instanceof(RpcValueWithMetaData);
export const rpcvalue = () => z.union([
z.undefined(),
z.boolean(),
z.number(),
uint(),
z.instanceof(Double),
z.instanceof(Decimal),
z.instanceof(ArrayBuffer),
double(),
decimal(),
blob(),
z.string(),
z.date(),
z.array(z.any()),
Expand Down

0 comments on commit 9183777

Please sign in to comment.