libshv-js 3.1.2 → 3.1.3

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.
@@ -18,6 +18,9 @@ jobs:
18
18
  steps:
19
19
  - uses: actions/checkout@v3
20
20
 
21
+ - name: Install dependencies
22
+ run: npm install
23
+
21
24
  - name: Compile
22
25
  run: npx tsc
23
26
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libshv-js",
3
- "version": "3.1.2",
3
+ "version": "3.1.3",
4
4
  "description": "Typescript implementation of libshv",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -21,10 +21,12 @@
21
21
  "./cpon.ts": "./src/cpon.ts",
22
22
  "./rpcmessage.ts": "./src/rpcmessage.ts",
23
23
  "./rpcvalue.ts": "./src/rpcvalue.ts",
24
- "./ws-client.ts": "./src/ws-client.ts"
24
+ "./ws-client.ts": "./src/ws-client.ts",
25
+ "./zod.ts": "./src/zod.ts"
25
26
  },
26
27
  "devDependencies": {
27
28
  "typescript": "^5.5.4",
28
- "xo": "^0.59.3"
29
+ "xo": "^0.59.3",
30
+ "zod": "^3.23.8"
29
31
  }
30
32
  }
package/src/zod.ts ADDED
@@ -0,0 +1,8 @@
1
+ import {z, type ZodType} from 'zod';
2
+ import {IMap, Int, type RpcValue, ShvMap} from './rpcvalue';
3
+
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) => data instanceof ShvMap && z.object(schema).safeParse(data.value).success);
5
+ 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) => data instanceof IMap && z.object(schema).safeParse(data.value).success);
6
+ export const int = () => z.custom<Int>((data: RpcValue) => data instanceof Int);
7
+
8
+ export * from 'zod';